std::round, std::roundf, std::roundl, std::lround, std::lroundf, std::lroundl, std::llround, std::llroundf
From cppreference.com
Defined in header <cmath>
|
||
Rounding to floating-point types |
||
(1) | ||
float round ( float num ); double round ( double num ); |
(since C++11) (until C++23) |
|
constexpr /* floating-point-type */ round ( /* floating-point-type */ num ); |
(since C++23) | |
float roundf( float num ); |
(2) | (since C++11) (constexpr since C++23) |
long double roundl( long double num ); |
(3) | (since C++11) (constexpr since C++23) |
Rounding to long |
||
(4) | ||
long lround ( float num ); long lround ( double num ); |
(since C++11) (until C++23) |
|
constexpr long lround( /* floating-point-type */ num ); |
(since C++23) | |
long lroundf( float num ); |
(5) | (since C++11) (constexpr since C++23) |
long lroundl( long double num ); |
(6) | (since C++11) (constexpr since C++23) |
Rounding to long long |
||
(7) | ||
long long llround ( float num ); long long llround ( double num ); |
(since C++11) (until C++23) |
|
constexpr long long llround( /* floating-point-type */ num ); |
(since C++23) | |
long long llroundf( float num ); |
(8) | (since C++11) (constexpr since C++23) |
long long llroundl( long double num ); |
(9) | (since C++11) (constexpr since C++23) |
Defined in header <cmath>
|
||
template< class Integer > double round( Integer num ); |
(A) | (since C++11) (constexpr since C++23) |
template< class Integer > long lround( Integer num ); |
(B) | (since C++11) (constexpr since C++23) |
template< class Integer > long long llround( Integer num ); |
(C) | (since C++11) (constexpr since C++23) |
1-3) Computes the nearest integer value to num (in floating-point format), rounding halfway cases away from zero, regardless of the current rounding mode. The library provides overloads of
std::round
for all cv-unqualified floating-point types as the type of the parameter num.(since C++23)4-9) Computes the nearest integer value to num (in integer format), rounding halfway cases away from zero, regardless of the current rounding mode. The library provides overloads of
std::lround
and std::llround
for all cv-unqualified floating-point types as the type of the parameter num.(since C++23)A-C) Additional overloads are provided for all integer types, which are treated as double.
Contents |
[edit] Parameters
num | - | floating-point or integer value |
[edit] Return value
If no errors occur, the nearest integer value to num, rounding halfway cases away from zero, is returned.
Return value
num
If a domain error occurs, an implementation-defined value is returned.
[edit] Error handling
Errors are reported as specified in math_errhandling.
If the result of std::lround
or std::llround
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
std::round
function:- The current rounding mode has no effect.
- If num is ±∞, it is returned, unmodified.
- If num is ±0, it is returned, unmodified.
- If num is NaN, NaN is returned.
- For
std::lround
andstd::llround
functions:- FE_INEXACT is never raised.
- The current rounding mode has no effect.
- If num 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 num is NaN, FE_INVALID is raised and an implementation-defined value is returned.