首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::numeric_limits::round_style

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<T>::round_style

/* 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_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

...

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 © cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券