Return a rounded integer value
#include <math.h> double nearbyint( double x); float nearbyintf( float x); long double nearbyintl( long double x);
The nearbyint(), nearbyintf(), and nearbyintl() functions round their argument to an integer value in floating-point format, using the current rounding direction and without raising the inexact floating-point exception.
To check for error situations, use feclearexcept() and fetestexcept(). For example:
The rounded integer value, with the same sign as x.
If x is: | These functions return: | Errors: |
---|---|---|
±0.0 | ±0.0 | — |
±Inf | x | — |
NaN | NaN | — |
These functions raise FE_INEXACT if the FPU reports that the result can't be exactly represented as a floating-point number.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |