Extreme numeric values ​​exactly floating point in R

Can someone please explain the following result to me. I know this has something to do with floating point precision, but the magnitude order (difference 1e308) surprises me.

0: high precision

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

1: very fuzzy

> 1 - 1e-16 == 1
[1] FALSE
> 1 - 1e-17 == 1
[1] TRUE
+6
source share
2 answers

R uses the IEEE 754 double-precision floating-point numbers.

Floating-point numbers are denser near zero. This is the result of the fact that they are designed to accurately calculate (the equivalent of about 16 significant decimal digits, as you noticed) over a very wide range.

, . , , , .

:

+-+-+-+--+--+--+----+----+----+--------+--------+--------+--
0

2 . . 2 -53 2 -52 .

+10

@PascalCuoq, FP R , IEEE 754 (, x86), 16 :

# Machine ULP in decimal digits...
.Machine$double.ulp.digits * log10(2)
-15.65...

# Note the direct relationship between ULP digits and EPS:
.Machine$double.ulp.digits = -52 
2.22 e-16 = .Machine$double.eps == 2^.Machine$double.ulp.digits

, 1 - 1e-16 ULP, 1 - 1e-17 ULP FP 1.0.

. R .Machine: " ". , EPS ULP.

(ULP FP. FP, )

, 1e-323: ULP FP, .

FP e-308 IEEE 754 ...

# Minimum-representable normalized positive FP value is...
.Machine$double.xmin
2.225..e-308

# ...which would correspond to this base-2 exponent...
log10(.Machine$double.xmin) / log10(2)
-1022
# ...or this base-10 exponent...
.Machine$double.min.exp * log10(2)
-307.65...

, FP, 0. , , FP - 1e-324 1e-323. , 52 , 2 ^ 51 10 ^ 15,35 :

# Exponent of Minimum-representable UNnormalized positive FP value 
log10(.Machine$double.xmin) - (.Machine$double.digits * log10(2))
-323.607...

( ? IEEE-754 )

( , , base-2: .Machine$double.base = 2)

+6

All Articles