roundeven, roundevenf, roundevenl
来自 cppreference.cn
定义于头文件 <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) |
四舍五入到最接近的整数,在半数情况下远离零 (函数) |