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

std::numeric_limits::digits10

STD::数字[医]*数字10

static const int digits10;(until C++11)
static constexpr int digits10(since C++11)

价值std::numeric_limits<T>::digits10可以由类型表示的基-10位数。T如果没有改变,也就是任何有这么多小数位数的数字都可以转换成一个类型的值。T并返回到十进制形式,不因四舍五入或溢出而更改。作为基地-根类型,它是位数%28digits-1对于浮点类型,%29乘日志

10%28基数%29,四舍五入。

标准专业化

Tvalue of std::numeric_limits::digits10
/* non-specialized */​0​
bool​0​
charstd::numeric_limits<char>::digits * std::log10(2)
signed charstd::numeric_limits<signed char>::digits * std::log10(2)
unsigned charstd::numeric_limits<unsigned char>::digits * std::log10(2)
wchar_tstd::numeric_limits<wchar_t>::digits * std::log10(2)
char16_tstd::numeric_limits<char16_t>::digits * std::log10(2)
char32_tstd::numeric_limits<char32_t>::digits * std::log10(2)
shortstd::numeric_limits<short>::digits * std::log10(2)
unsigned shortstd::numeric_limits<unsigned short>::digits * std::log10(2)
intstd::numeric_limits<int>::digits * std::log10(2)
unsigned intstd::numeric_limits<unsigned int>::digits * std::log10(2)
longstd::numeric_limits<long>::digits * std::log10(2)
unsigned longstd::numeric_limits<unsigned long>::digits * std::log10(2)
long longstd::numeric_limits<long long>::digits * std::log10(2)
unsigned long longstd::numeric_limits<unsigned long long>::digits * std::log10(2)
floatFLT_DIG
doubleDBL_DIG
long doubleLDBL_DIG

8位二进制类型可以精确地表示任何两位小数,但3位小数256.999不能表示.。价值digits108位类型是2%288*std::log10(2)是2.41%29。

标准的32位ieee 754浮点类型有一个24位小数部分%2823位写入,其中一个隐含%29,这可能意味着它可以代表7位小数%28。24*std::log10(2)为7.22%29,但相对四舍五入的误差是不一致的,有些浮点值有7个小数位数,不能转换为32位浮点数并返回:最小的正示例是8.589973e9,变成8.589974e9在往返之后。这些舍入错误在表示中不能超过一位,并且digits10计算为(24-1)*std::log10(2),也就是6.92。舍入结果为6。

另见

radix staticthe radix or integer base used by the representation of the given type (public static member constant)
digits staticnumber of radix digits that can be represented without change (public static member constant)
min_exponent staticone more than the smallest negative power of the radix that is a valid normalized floating-point value (public static member constant)
max_exponent staticone more than the largest integer power of the radix that is a valid finite floating-point value (public static member constant)

© cppreference.com

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

http://en.cppreference.com/w/cpp/type/NUMERIC[医]极限/数字10