rintf, rintl, rint, rintd32, rintd64, or rintd128 Subroutine

Purpose

Rounds to the nearest integral value.

Syntax

#include <math.h>

float rintf (x)
float x;

long double rintl (x)
long double x;

double rint (x)
double x;

_Decimal32 rintd32(x)
_Decimal32 x;
       
_Decimal64 rintd64(x)
_Decimal64 x;
       
_Decimal128 rintd128(x)
_Decimal128 x;

Description

The rintf, rintl, rint, rintd32, rintd64, and rintd128 subroutines return the integral value (represented as a floating-point number) nearest x in the direction of the current rounding mode. The current rounding mode is implementation-defined.

The rintf, rintl, rint, rintd32, rintd64, and rintd128 subroutines differ from the nearbyint, nearbyintf, nearbyintl, nearbyintd32, nearbyintd64, and nearbyintd128 subroutines only in that they may raise the inexact floating-point exception if the result differs in value from the argument.

An application wishing to check for error situations should set the errno global variable to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these subroutines. Upon return, if errno is nonzero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is nonzero, an error has occurred.

Parameters

Item Description
x Specifies the value to be rounded.

Return Values

Upon successful completion, the rintf, rintl, rint, rintd32, rintd64, and rintd128 subroutines return the integer (represented as a floating-point number) nearest x in the direction of the current rounding mode.

If x is NaN, a NaN is returned.

If x is ±0 or ±Inf, x is returned.

If the correct value would cause overflow, a range error occurs the rintf, rintl, rint, rintd32, rintd64, and rintd128 subroutines return the value of the macro ±HUGE_VALF, ±HUGE_VALL, ±HUGE_VAL, ±HUGE_VAL_D32, ±HUGE_VAL_D64, and ±HUGE_VAL_D128 (with the same sign as x), respectively.