roundeven, roundevenf, roundevenl
来自 cppreference.cn
定义于头文件 <math.h> |
||
float roundevenf( float arg ); |
(1) | (since C23) |
double roundeven( double arg ); |
(2) | (since C23) |
long double roundevenl( long double arg ); |
(3) | (since C23) |
定义于头文件 <tgmath.h> |
||
#define roundeven( arg ) |
(4) | (since 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 The roundeven functions (p: 265-266)
- 7.27 Type-generic math <tgmath.h> (p: 386-390)
- F.10.6.8 The roundeven functions (p: 532)
[编辑] 参见
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) |
使用当前舍入模式将数字舍入为整数,如果结果不同,则 异常 (函数) |
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) |
舍入到最接近的整数,在中间情况下远离零舍入 (函数) |