std::numeric_limits::round_style
STD::数字[医]限制::圆[医]风格
static const std::float_round_style round_style | | (until C++11) |
---|---|---|
static constexpr std::float_round_style round_style | | (since C++11) |
价值std::numeric_limits<T>::round_style标识浮点类型使用的舍入样式。T的可修复值之一。T存储在该类型的对象中。
标准专业化
T | value of std::numeric_limits |
---|---|
/* non-specialized */ | std::round_toward_zero |
bool | std::round_toward_zero |
char | std::round_toward_zero |
signed char | std::round_toward_zero |
unsigned char | std::round_toward_zero |
wchar_t | std::round_toward_zero |
char16_t | std::round_toward_zero |
char32_t | std::round_toward_zero |
short | std::round_toward_zero |
unsigned short | std::round_toward_zero |
int | std::round_toward_zero |
unsigned int | std::round_toward_zero |
long | std::round_toward_zero |
unsigned long | std::round_toward_zero |
long long | std::round_toward_zero |
unsigned long long | std::round_toward_zero |
float | usually std::round_to_nearest |
double | usually std::round_to_nearest |
long double | usually std::round_to_nearest |
注记
这些值是常量,不反映std::fesetround
更改后的值可从FLT_ROUNDS
或std::fegetround
...
例
十进制值0.1
不能用二进制浮点类型表示.。当存储在ieee-745中时double
,它介于0x1.9999999999999之间。%2A2-4
和0x1.9999999999999999999999 a%2A2-4
.舍入到最近可表示值的四舍五入结果为0x1.9999999999999999a%2A2-4
...
同样,十进制值0.3,介于0x1.33333333333之间。%2A2-2
和0x1.33333333334%2A2-2
被舍入到最近,并存储为0x1.3333333333333。%2A2-2
...
二次
#include <iostream>
#include <limits>
int main()
{
std::cout << std::hexfloat << "The decimal 0.1 is stored in a double as "
<< 0.1 << '\n'
<< "The decimal 0.3 is stored in a double as "
<< 0.3 << '\n'
<< "The rounding style is " << std::numeric_limits<double>::round_style << '\n';
}
二次
产出:
二次
The decimal 0.1 is stored in a double as 0x1.999999999999ap-4
The decimal 0.3 is stored in a double as 0x1.3333333333333p-2
The rounding style is 1
二次
另见
float_round_style | indicates floating-point rounding modes (enum) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。