rint, rintf, rintl, lrint, lrintf, lrintl, llrint, llrintf, llrintl
Defined in header <math.h>
|
||
float rintf( float arg ); |
(1) | (since C99) |
double rint( double arg ); |
(2) | (since C99) |
long double rintl( long double arg ); |
(3) | (since C99) |
Defined in header <tgmath.h>
|
||
#define rint( arg ) |
(4) | (since C99) |
Defined in header <math.h>
|
||
long lrintf( float arg ); |
(5) | (since C99) |
long lrint( double arg ); |
(6) | (since C99) |
long lrintl( long double arg ); |
(7) | (since C99) |
Defined in header <tgmath.h>
|
||
#define lrint( arg ) |
(8) | (since C99) |
Defined in header <math.h>
|
||
long long llrintf( float arg ); |
(9) | (since C99) |
long long llrint( double arg ); |
(10) | (since C99) |
long long llrintl( long double arg ); |
(11) | (since C99) |
Defined in header <tgmath.h>
|
||
#define llrint( arg ) |
(12) | (since C99) |
arg
to an integer value in floating-point format, using the current rounding mode.arg
to an integer value in integer format, using the current rounding mode.arg
has type long double, rintl
, lrintl
, llrintl
is called. Otherwise, if arg
has integer type or the type double, rint
, lrint
, llrint
is called. Otherwise, rintf
, lrintf
, llrintf
is called, respectively.Parameters
arg | - | floating point value |
Return value
If no errors occur, the nearest integer value to arg
, according to the current rounding mode, is returned.
Error handling
Errors are reported as specified in math_errhandling.
If the result of lrint
or llrint
is outside the range representable by the return type, a domain error or a range error may occur.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- For the
rint
function:
- If
arg
is ±∞, it is returned, unmodified - If
arg
is ±0, it is returned, unmodified - If
arg
is NaN, NaN is returned
- For
lrint
andllrint
functions:
- If
arg
is ±∞, FE_INVALID is raised and an implementation-defined value is returned - If the result of the rounding is outside the range of the return type, FE_INVALID is raised and an implementation-defined value is returned
- If
arg
is NaN, FE_INVALID is raised and an implementation-defined value is returned
Notes
POSIX specifies that all cases where lrint
or llrint
raise FE_INEXACT are domain errors.
As specified in math_errhandling, FE_INEXACT may be (but isn't required to be on non-IEEE floating-point platforms) raised by rint
when rounding a non-integer finite value.
The only difference between rint
and nearbyint is that nearbyint never raises FE_INEXACT.
The largest representable floating-point values are exact integers in all standard floating-point formats, so rint
never overflows on its own; however the result may overflow any integer type (including intmax_t), when stored in an integer variable.
If the current rounding mode is...
- FE_DOWNWARD, then
rint
is equivalent to floor. - FE_UPWARD, then
rint
is equivalent to ceil. - FE_TOWARDZERO, then
rint
is equivalent to trunc - FE_TONEAREST, then
rint
differs from round in that halfway cases are rounded to even rather than away from zero.