我要评分
获取效率
正确性
完整性
易理解

rint

Return the rounded value of x based on the current rounding mode.

Interface Definition

C interface:

float rintf(float x);

double rint(double x);

long double rintl(long double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For rintf, x is of single-precision floating-point type.
  • For rint, x is of double-precision floating-point type.
  • For rintl, x is of long double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • The rounded value of x is returned. x ∈ (-inf, inf)
  • If the input is +0, the return value is +0.
  • If the input is -0, the return value is -0.
  • If the input is ±∞, the return value is ±∞.
  • If the input is NaN, the return value is NaN.

Dependency

C: "km.h"

Example

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
     * */