roundeven, roundevenf, roundevenl
來自 cppreference.com
定義於標頭檔案 <math.h> |
||
float roundevenf( float arg ); |
(1) | (自 C23 起) |
double roundeven( double arg ); |
(2) | (自 C23 起) |
long double roundevenl( long double arg ); |
(3) | (自 C23 起) |
定義於標頭檔案 <tgmath.h> |
||
#define roundeven( arg ) |
(4) | (自 C23 起) |
1-3) 計算 arg 的最接近的整數值(以浮點格式),將中間值舍入到最接近的偶數整數,而不考慮當前舍入模式。
4) 型別通用宏:如果 arg 的型別是 long double,則呼叫
roundevenl
。否則,如果 arg 具有整數型別或型別 double,則呼叫 roundeven
。否則,分別呼叫 roundevenf
。目錄 |
[編輯] 引數
arg | - | 浮點值 |
[編輯] 返回值
如果沒有發生錯誤,則返回 arg 的最接近的整數值,中間值舍入到最接近的偶數整數。
[編輯] 錯誤處理
此函式不受 math_errhandling
中指定的任何錯誤的影響。
如果實現支援 IEEE 浮點算術 (IEC 60559)
- FE_INEXACT 從不引發。
- 如果 arg 是 ±∞,則返回它,不作修改。
- 如果 arg 是 ±0,則返回它,不作修改。
- 如果 arg 是 NaN,則返回 NaN。
[編輯] 示例
執行此程式碼
#include <math.h> #include <stdio.h> int main(void) { printf("roundeven(+2.4) = %+.1f\n", roundeven(2.4)); printf("roundeven(-2.4) = %+.1f\n", roundeven(-2.4)); printf("roundeven(+2.5) = %+.1f\n", roundeven(2.5)); printf("roundeven(-2.5) = %+.1f\n", roundeven(-2.5)); printf("roundeven(+2.6) = %+.1f\n", roundeven(2.6)); printf("roundeven(-2.6) = %+.1f\n", roundeven(-2.6)); printf("roundeven(+3.5) = %+.1f\n", roundeven(3.5)); printf("roundeven(-3.5) = %+.1f\n", roundeven(-3.5)); printf("roundeven(-0.0) = %+.1f\n", roundeven(-0.0)); printf("roundeven(-Inf) = %+f\n", roundeven(-INFINITY)); }
可能的輸出
roundeven(+2.4) = +2.0 roundeven(-2.4) = -2.0 roundeven(+2.5) = +2.0 roundeven(-2.5) = -2.0 roundeven(+2.6) = +3.0 roundeven(-2.6) = -3.0 roundeven(+3.5) = +4.0 roundeven(-3.5) = -4.0 roundeven(-0.0) = -0.0 roundeven(-Inf) = -inf
[編輯] 參考
- C23 標準 (ISO/IEC 9899:2024)
- 7.12.9.8 roundeven 函式 (p: 265-266)
- 7.27 型別通用數學 <tgmath.h> (p: 386-390)
- F.10.6.8 roundeven 函式 (p: 532)
[編輯] 參閱
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) |
使用當前舍入模式四捨五入到整數 如果結果不同則丟擲異常 (函式) |
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) |
四捨五入到最接近的整數,在半數情況下遠離零 (函式) |