Plinth
Plinth

Reputation: 289

Precision of scientific notation in R

How accurate is scientific notation in R? I'm generating data that as values like this:

-5.59924596431885e-320

Is this an accurate value? I know R is usual only accurate to 15 decimal places when the number is written like this:

-2.1411372887

So is the scientific notation accurate at such small numbers?

Upvotes: 0

Views: 1778

Answers (2)

Severin Pappadeux
Severin Pappadeux

Reputation: 20080

If you're using IEEE-754 doubles in R (and I'm 99.99% sure you are), there are two minimum values:

  1. Normalized minimum, which, as @mrip said, is about 2.22507e-308

  2. Denormalized minimum, which is about 4.94066e-324

Moral of the story: you're getting denorms in your calculation, and no, they cannot be accurate to 15 decimal places

Upvotes: 2

mrip
mrip

Reputation: 15163

This isn't really a question about R, but a question about floating point representation. Normal doubles are accurate to 15 or 16 decimal digits. However, the smallest normal double is 2^-1022, or 2.225074e-308. Values smaller then this can be represented by doubles, but you start to lose precision, because the significand will be padded with zeros. So, for example, 1e-320 will only be accurate to about 3 or 4 decimal digits, since it is about 10^12 times smaller than min_double.

See: https://en.wikipedia.org/wiki/Denormal_number

The values of max and min double and machine epsilon are stored in R as .Machine. On my computer:

> .Machine
$double.eps
[1] 2.220446e-16

$double.neg.eps
[1] 1.110223e-16

$double.xmin
[1] 2.225074e-308

$double.xmax
[1] 1.797693e+308

$double.base
[1] 2

$double.digits
[1] 53

$double.rounding
[1] 5

$double.guard
[1] 0

$double.ulp.digits
[1] -52

$double.neg.ulp.digits
[1] -53

$double.exponent
[1] 11

$double.min.exp
[1] -1022

$double.max.exp
[1] 1024

$integer.max
[1] 2147483647

$sizeof.long
[1] 8

$sizeof.longlong
[1] 8

$sizeof.longdouble
[1] 16

$sizeof.pointer
[1] 8

Upvotes: 3

Related Questions