std::nearbyint,std::nearbyintf,std::nearbyintl (3) - Linux Manuals
Defined in header <cmath>
float nearbyint ( float arg ); (1) (since C++11)
float nearbyintf( float arg );
double nearbyint ( double arg ); (2) (since C++11)
long double nearbyint ( long double arg ); (3) (since C++11)
long double nearbyintl( long double arg );
double nearbyint ( IntegralType arg ); (4) (since C++11)
1-3) Rounds the floating-point argument arg to an integer value in floating-point format, using the current_rounding_mode.
4) A set of overloads or a function template accepting an argument of any integral_type. Equivalent to (2) (the argument is cast to double).
arg - floating point value
The nearest integer value to arg, according to the current_rounding_mode, is returned.
This function is not subject to any of the errors specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
* FE_INEXACT is never raised
* If arg is ±∞, it is returned, unmodified
* If arg is ±0, it is returned, unmodified
* If arg is NaN, NaN is returned
The only difference between std::nearbyint and std::rint 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::nearbyint 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_TONEAREST, this function rounds to even in halfway cases (like rint, but unlike round).
// Run this code
llrintf nearest integer using current rounding mode with
llrintl exception if the result differs
llroundl nearest integer, rounding away from zero in halfway cases
fesetround gets or sets rounding direction