rint, rintf, rintl

Rounds a floating-point value to the nearest integer in floating-point format.


double rint( double x );
float rintf( float x );
long double rintl( long double x );
float rint( float x );  // C++ only
long double rint( long double x );  // C++ only


The floating-point value to round.

Return Value

The rint functions return a floating-point value that represents the nearest integer to x. Halfway values are rounded according to the current setting of the floating-point rounding mode, the same as the nearbyint functions. Unlike the nearbyint functions, the rint functions may raise the FE_INEXACT floating-point exception if the result differs in value from the argument. There is no error return.

Input SEH Exception _matherr Exception
± ∞, QNAN, IND none none


Because C++ allows overloading, you can call overloads of rint that take and return float and long double values. In a C program, rint always takes and returns a double.


Function C header C++ header
rint, rintf, rintl <math.h> <cmath>

For additional compatibility information, see Compatibility.


// crt_rint.c
// Build with: cl /W3 /Tc crt_rint.c
// This example displays the rounded results of
// the floating-point values 2.499999, -2.499999,
// 2.8, -2.8, 2.5 and -2.5.

#include <math.h>
#include <stdio.h>

int main( void )
   double x = 2.499999;
   float y = 2.8f;
   long double z = 2.5;

   printf("rint(%f) is %.0f\n", x, rint (x));
   printf("rint(%f) is %.0f\n", -x, rint (-x));
   printf("rintf(%f) is %.0f\n", y, rintf(y));
   printf("rintf(%f) is %.0f\n", -y, rintf(-y));
   printf("rintl(%Lf) is %.0Lf\n", z, rintl(z));
   printf("rintl(%Lf) is %.0Lf\n", -z, rintl(-z));
rint(2.499999) is 2
rint(-2.499999) is -2
rintf(2.800000) is 3
rintf(-2.800000) is -3
rintl(2.500000) is 3
rintl(-2.500000) is -3

See also

Floating-Point Support
ceil, ceilf, ceill
floor, floorf, floorl
fmod, fmodf
lrint, lrintf, lrintl, llrint, llrintf, llrintl
lround, lroundf, lroundl, llround, llroundf, llroundl
nearbyint, nearbyintf, nearbyintl