std::rint,std::rintf,std::rintl,std::lrint,std::lrintf,std::lrintl,std::llrint,std::llrintf (3) - Linux Manuals
std::rint,std::rintf,std::rintl,std::lrint,std::lrintf,std::lrintl,std::llrint,std::llrintf: std::rint,std::rintf,std::rintl,std::lrint,std::lrintf,std::lrintl,std::llrint,std::llrintf
NAME
std::rint,std::rintf,std::rintl,std::lrint,std::lrintf,std::lrintl,std::llrint,std::llrintf - std::rint,std::rintf,std::rintl,std::lrint,std::lrintf,std::lrintl,std::llrint,std::llrintf
Synopsis
Defined in header <cmath>
float rint ( float arg ); (1) (since C++11)
float rintf( float arg );
double rint ( double arg ); (2) (since C++11)
long double rint ( long double arg ); (3) (since C++11)
long double rintl( long double arg );
double rint ( IntegralType arg ); (4) (since C++11)
long lrint ( float arg ); (5) (since C++11)
long lrintf( float arg );
long lrint ( double arg ); (6) (since C++11)
long lrint ( long double arg ); (7) (since C++11)
long lrintl( long double arg );
long lrint ( IntegralType arg ); (8) (since C++11)
long long llrint ( float arg ); (9) (since C++11)
long long llrintf( float arg );
long long llrint ( double arg ); (10) (since C++11)
long long llrint ( long double arg ); (11) (since C++11)
long long llrintl( long double arg );
long long llrint ( IntegralType arg ); (12) (since C++11)
1-3) Rounds the floating-point argument arg to an integer value (in floating-point format), using the current_rounding_mode.
5-7, 9-11) Rounds the floating-point argument arg to an integer value, using the current_rounding_mode.
4,8,12) A set of overloads or a function template accepting an argument of any integral_type. Equivalent to (2,6,10), respectively (the argument is cast to double).
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 std::lrint or std::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),
* If arg is ±∞, it is returned, unmodified
* If arg is ±0, it is returned, unmodified
* If arg is NaN, NaN is returned
* 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 std::lrint or std::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 std::rint when rounding a non-integer finite value.
The only difference between std::rint and std::nearbyint is that std::nearbyint never raises FE_INEXACT.
The largest representable floating-point values are exact integers in all standard floating-point formats, so std::rint never overflows on its own; however the result may overflow any integer type (including std::intmax_t), when stored in an integer variable.
If the current rounding mode is...
* FE_DOWNWARD, then std::rint is equivalent to std::floor.
* FE_UPWARD, then std::rint is equivalent to std::ceil.
* FE_TOWARDZERO, then std::rint is equivalent to std::trunc
* FE_TONEAREST, then std::rint differs from std::round in that halfway cases are rounded to even rather than away from zero.
Example
// Run this code