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

std::numeric_limits::digits10

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,四舍五入。

标准专业化

T

value of std::numeric_limits<T>::digits10

/* non-specialized */

?0?

bool

?0?

char

std::numeric_limits<char>::digits * std::log10(2)

signed char

std::numeric_limits<signed char>::digits * std::log10(2)

unsigned char

std::numeric_limits<unsigned char>::digits * std::log10(2)

wchar_t

std::numeric_limits<wchar_t>::digits * std::log10(2)

char16_t

std::numeric_limits<char16_t>::digits * std::log10(2)

char32_t

std::numeric_limits<char32_t>::digits * std::log10(2)

short

std::numeric_limits<short>::digits * std::log10(2)

unsigned short

std::numeric_limits<unsigned short>::digits * std::log10(2)

int

std::numeric_limits<int>::digits * std::log10(2)

unsigned int

std::numeric_limits<unsigned int>::digits * std::log10(2)

long

std::numeric_limits<long>::digits * std::log10(2)

unsigned long

std::numeric_limits<unsigned long>::digits * std::log10(2)

long long

std::numeric_limits<long long>::digits * std::log10(2)

unsigned long long

std::numeric_limits<unsigned long long>::digits * std::log10(2)

float

FLT_DIG

double

DBL_DIG

long double

LDBL_DIG

8位二进制类型可以精确地表示任何两位小数,但3位小数256.999不能表示.。价值digits108位类型是2%28。8*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 static

the radix or integer base used by the representation of the given type (public static member constant)

digits static

number of radix digits that can be represented without change (public static member constant)

min_exponent static

one more than the smallest negative power of the radix that is a valid normalized floating-point value (public static member constant)

max_exponent static

one more than the largest integer power of the radix that is a valid finite floating-point value (public static member constant)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com