Previous Page
Next Page

lrint

Rounds a floating-point number to an integer

#include <math.h>
long lrint ( double x  );
long lrintf ( float x  );
long lrintl ( long double x  );

The lrint( ) functions round a floating-point number to the next integer value in the current rounding direction. If the result is outside the range of long, a range error may occur, depending on the implementation, and the return value is unspecified.

Example

double t_ambient;          // Ambient temperature in Celsius.
int t_display;             // Display permits integer values.
char tempstring[128];
int saverounding = fegetround( );

/* ... Read t_ambient from some thermometer somewhere ... */

fesetround( FE_TONEAREST );   // Round toward nearest integer, up or down.

t_display = (int)lrint( t_ambient );
snprintf( tempstring, 128, "Current temperature: %d° C\n", t_display );

fesetround( saverounding );  // Restore rounding direction.

See Also

rint( ), llrint( ), round( ), lround( ), llround( ), nearbyint( )


Previous Page
Next Page