std::numeric_limits::round_style

static const std::float_round_style round_style
(C++11 前)
static constexpr std::float_round_style round_style
(C++11 起)

std::numeric_limits<T>::round_style 的值鉴别浮点类型 T 在凡将不能以 T 的值表示的值存储于该类型的对象时所用的舍入模式。

目录

标准特化

T 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 通常为 std::round_to_nearest
double 通常为 std::round_to_nearest
long double 通常为 std::round_to_nearest

注意

这些值是常量,且不反映 std::fesetround 所做的舍入模式更改。被更改的值可从 FLT_ROUNDSstd::fegetround 获得。

示例

十进制值 0.1 不能表示成二进制浮点类型。在存储于 IEEE-745 double 时,它落入 0x1.9999999999999*2-4
0x1.999999999999a*2-4
之间。舍入到最近可表示结果导致 0x1.999999999999a*2-4

同样地,十进制值 0.3 在 0x1.3333333333333*2-2
0x1.3333333333334*2-2
之间,舍入到最近值后存储为 0x1.3333333333333*2-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

参阅

指示浮点舍入模式
(枚举)

版本历史

  • (当前 | 先前 2017年6月9日 (五) 23:37Fruderica讨论 | 贡献. . (3,253字节) (-1,151). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 18:18P12bot讨论 | 贡献 . . (4,404字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 11:53P12bot讨论 | 贡献 . . (4,404字节) (-270). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 14:28P12bot讨论 | 贡献 . . (4,674字节) (+353). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月27日 (六) 12:43P12讨论 | 贡献 . . (4,321字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (4,321字节) (-53). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 03:55P12讨论 | 贡献 . . (4,374字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (4,374字节) (+4,374). . (Translated from the English version using Google Translate)