R中浮点精度的极端数值 [英] Extreme numerical values in floating-point precision in R
问题描述
0:高精度
> 1e-324 == 0
[1] TRUE
> 1e-323 == 0
[1] FALSE
<1>非常不正确
> 1 - 1e-16 == 1
[1] FALSE
> 1 - 1e-17 == 1
[1] TRUE
浮点数在零附近更密集。这是他们被设计为在很宽的范围内精确计算(相当于大约16位十进制数字的结果)的结果。
一个统一的绝对精度的定点系统。在实践中,定点要么浪费,要么事先仔细地估计每个中间计算的范围,如果它们是错误的,会产生严重的后果。正浮点数示意图:
+ - + - + - + - + - + - + ---- + - + ---- + -------- + -------- + -------- + -
0
最小正指数的双精度数是2的最小指数的幂。接近1的双精度浮点数已经相当宽。从一个到它下面的数字之间有一个2 -53的距离,从一个到上面的数字的距离是2 -52。 b $ b
Can somebody please explain me the following output. I know that it has something to do with floating point precision, but the order of magnitue (difference 1e308) surprises me.
0: high precision
> 1e-324==0
[1] TRUE
> 1e-323==0
[1] FALSE
1: very unprecise
> 1 - 1e-16 == 1
[1] FALSE
> 1 - 1e-17 == 1
[1] TRUE
R uses IEEE 754 double-precision floating-point numbers.
Floating-point numbers are more dense near zero. This is a result of their being designed to compute accurately (the equivalent of about 16 significant decimal digits, as you have noticed) over a very wide range.
Perhaps you expected a fixed-point system with uniform absolute precision. In practice fixed-point is either wasteful or the ranges of each intermediate computation must be carefully estimated beforehand, with drastic consequences if they are wrong.
Positive floating-point numbers look like this, schematically:
+-+-+-+--+--+--+----+----+----+--------+--------+--------+-- 0
The smallest positive normal double-precision number is 2 to the power of the minimal exponent. Near one, the double-precision floating-point numbers are already spread quite wide apart. There is a distance of 2-53 from one to the number below it, and a distance of 2-52 from one to the number above it.
这篇关于R中浮点精度的极端数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!