在线文档教程
C++
应用 | Utilities

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存储在该类型的对象中。

标准专业化

Tvalue of std::numeric_limits::round_style
/* non-specialized */std::round_toward_zero
boolstd::round_toward_zero
charstd::round_toward_zero
signed charstd::round_toward_zero
unsigned charstd::round_toward_zero
wchar_tstd::round_toward_zero
char16_tstd::round_toward_zero
char32_tstd::round_toward_zero
shortstd::round_toward_zero
unsigned shortstd::round_toward_zero
intstd::round_toward_zero
unsigned intstd::round_toward_zero
longstd::round_toward_zero
unsigned longstd::round_toward_zero
long longstd::round_toward_zero
unsigned long longstd::round_toward_zero
floatusually std::round_to_nearest
doubleusually std::round_to_nearest
long doubleusually std::round_to_nearest

注记

这些值是常量,不反映std::fesetround更改后的值可从FLT_ROUNDSstd::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_styleindicates floating-point rounding modes (enum)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/type/NUMERIC[医]极限/圆[医]风格