C ++中的double类型数字 [英] double type digits in C++
问题描述
Ref:
http://msdn.microsoft.com/en-us/library/system.double(VS.80)。 aspx :
。
。
请记住,浮点数只能接近十进制数,而浮点数的精度决定了这个数的近似值十进制数字。默认情况下,Double值包含十五个精度的十进制数字,但内部最多保留17位数字。浮点数的精度有几个结果:
。
。
示例:
d1 = 97842111437.390091
d2 = 97842111437.390076
d1和d2小数点后16位和小数点17位的数字不应该是重要的。寻找方法迫使他们归零。即
d1 = 97842111437.390000
d2 = 97842111437.390000
反例:将两个最接近的浮点数转换为有理数
1.11111111111118
(有十进制数字15)是
1.1111111111111799942818834097124636173248291015625
1.1111111111111802163264883347437717020511627197265625
换句话说,没有浮点数以 1.1111111111111800
。
The IEE754 (64 bits) floating point is supposed to correctly represent 15 significant digit although the internal representation has 17 ditigs. Is there a way to force the 16th and 17th digits to zero ??
Ref: http://msdn.microsoft.com/en-us/library/system.double(VS.80).aspx : . .
Remember that a floating-point number can only approximate a decimal number, and that the precision of a floating-point number determines how accurately that number approximates a decimal number. By default, a Double value contains 15 decimal digits of precision, although a maximum of 17 digits is maintained internally. The precision of a floating-point number has several consequences: . .
Example nos:
d1 = 97842111437.390091
d2 = 97842111437.390076
d1 and d2 differ in 16th and 17th decimal places that are not supposed to be significant. Looking for ways to force them to zero. ie
d1 = 97842111437.390000
d2 = 97842111437.390000
No. Counter-example: the two closest floating-point numbers to a rational
1.11111111111118
(which has 15 decimal digits) are
1.1111111111111799942818834097124636173248291015625
1.1111111111111802163264883347437717020511627197265625
In other words, there is not floating-point number that starts with 1.1111111111111800
.
这篇关于C ++中的double类型数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!