December 2005
Beginner to intermediate
618 pages
20h 19m
English
lrint
Rounds a floating-point number to an integer
#include <math.h> longlrint( doublex); longlrintf( floatx); longlrintl( long doublex);
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.
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.Read now
Unlock full access