R中浮点精度的极端数值 [英] Extreme numerical values in floating-point precision in R

查看:171
本文介绍了R中浮点精度的极端数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我解释下面的输出。我知道这与浮点精度有关,但是magnitue(差异1e308)的顺序令我感到惊讶。

0:高精度

 > 1e-324 == 0 
[1] TRUE
> 1e-323 == 0
[1] FALSE



<1>非常不正确

 > 1  -  1e-16 == 1 
[1] FALSE
> 1 - 1e-17 == 1
[1] TRUE


解决方案< R使用IEEE 754双精度浮点数字。



浮点数在零附近更密集。这是他们被设计为在很宽的范围内精确计算(相当于大约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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆