lrint


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( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net