![]() |
![]() |
![]() |
Round to the nearest integral value
#include <math.h> double rint ( double x ); float rintf ( float x );
libm
The rint() and rintf() functions return the integral value nearest x in the direction of the current rounding mode.
If the current rounding mode rounds toward negative infinity, then rint() is identical to floor(). If the current rounding mode rounds toward positive infinity, then rint() is identical to ceil().
An integer (represented as a double precision number) nearest x in the direction of the current rounding mode (IEEE754).
If x is: | rint() returns: |
---|---|
+/-Infinity | x |
NAN | NAN |
No errors will occur.
#include <stdio.h> #include <errno.h> #include <inttypes.h> #include <math.h> #include <fpstatus.h> int main(int argc, char** argv) { double a, b; a = 0.7 ; b = rint(a); printf("Round Native mode %f -> %f \n", a, b); return(0); }
rint() is standard Unix; rintf() is ANSI (draft)
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
![]() |
![]() |
![]() |