Round numbers to an integer value in floating-point format.
#include <math.h>
double nearbyint (x)
double x;
float nearbyintf (x)
float x;
long double nearbyintl (x)
long double x;
_Decimal32 nearbyintd32(x)
_Decimal32 x;
_Decimal64 nearbyintd64(x)
_Decimal64 x;
_Decimal128 nearbyintd128(x)
_Decimal128 x;
The nearbyint, nearbyintf, nearbyintl, nearbyintd32, nearbyintd64, and nearbyintd128 subroutines round the x parameter to an integer value in floating-point format, using the current rounding direction and without raising the inexact floating-point exception.
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.
Item | Description |
---|---|
x | Specifies the value to be computed. |
Upon successful completion, the nearbyint, nearbyintf, nearbyintl, nearbyintd32, nearbyintd64, and nearbyintd128 subroutines return the rounded integer value.
If x is NaN, a NaN is returned.
If x is ±0, ±0 is returned.
If x is ±Inf, x is returned.
If the correct value would cause overflow, a range error occurs and the nearbyint, nearbyintf, nearbyintl, nearbyintd32, nearbyintd64, and nearbyintd128 subroutines return the value of the macro ±HUGE_VAL, ±HUGE_VALF, ±HUGE_VALL, ±HUGE_VAL_D32, ±HUGE_VAL_D64, ±HUGE_VAL_D128 (with the same sign as x), respectively.