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 The roundeven functions (第 265-266 页)
- 7.27 Type-generic math <tgmath.h> (第 386-390 页)
- F.10.6.8 The roundeven functions (第 532 页)
参阅
| (C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) |
使用当前舍入模式取整到整数,若结果有误则产生异常 (函数) |
| (C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) |
取整到最接近的整数,在相邻整数正中间时取远离零的数 (函数) |