rint
基于当前的舍入方向,返回x的舍入值。
接口定义
C interface:
float rintf(float x);
double rint(double x);
long double rintl(long 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; // print result printf("rint(0.0) = %.15f\n", rint(x1)); printf("rint(-0.0) = %.15f\n", rint(x2)); printf("rint(1.5) = %.15f\n", rint(x3)); printf("rint(-2.5) = %.15f\n", rint(x4)); printf("rint(INFINITY) = %.15f\n", rint(a)); printf("rint(-INFINITY) = %.15f\n", rint(b)); printf("rint(NAN) = %.15f\n", rint(c)); /* * rint(0.0) = 0.000000000000000 * rint(-0.0) = -0.000000000000000 * rint(1.5) = 2.000000000000000 * rint(-2.5) = -2.000000000000000 * rint(INFINITY) = inf * rint(-INFINITY) = -inf * rint(NAN) = nan * */
父主题: 舍入函数