nearbyint
基于当前的舍入方向,返回x的舍入值。
接口定义
C interface:
float nearbyintf(float x);
double nearbyint(double x);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
x |
|
表示输入数据的浮点值。 |
输入 |
返回值
- 返回x的舍入值,x ∈ (-inf, inf)。
- 输入+0,返回+0。
- 输入-0,返回-0。
- 输入±∞,返回±∞。
- 输入nan,返回nan。
依赖
C: "km.h"
示例
C interface:
// typical usage double x1 = 0.0, x2 = -0.0, x3 = 1.5, x4 = -2.5; // special handing double a = INFINITY, b = -INFINITY, c = NAN; // pnearbyint result printf("nearbyint(0.0) = %.15f\n", nearbyint(x1)); printf("nearbyint(-0.0) = %.15f\n", nearbyint(x2)); printf("nearbyint(1.5) = %.15f\n", nearbyint(x3)); printf("nearbyint(-2.5) = %.15f\n", nearbyint(x4)); printf("nearbyint(INFINITY) = %.15f\n", nearbyint(a)); printf("nearbyint(-INFINITY) = %.15f\n", nearbyint(b)); printf("nearbyint(NAN) = %.15f\n", nearbyint(c)); /* * nearbyint(0.0) = 0.000000000000000 * nearbyint(-0.0) = -0.000000000000000 * nearbyint(1.5) = 2.000000000000000 * nearbyint(-2.5) = -2.000000000000000 * nearbyint(INFINITY) = inf * nearbyint(-INFINITY) = -inf * nearbyint(NAN) = nan * */
父主题: 舍入函数