Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum evaluatable scientific value?

Tags:

r

Does R store the smallest possibly representable scientific value?

To clarify: on my current machine:

>1e-300
[1] 1e-300

While

>1e-400
[1] 0

Through trial and error I know it is somewhere around the e-324 mark on my machine (where it also starts losing precision).

>1e-324
[1] 0
>5e-324
[1] 4.940656e-324

I've searched through the .Machine list and none of the values it stores contain either the value, or the exponent I'm looking for.

Edit:

Linked threads on the side indicate that this should be .Machine$double.eps, which is 2.220446e-16. Clearly this is no longer the case?

like image 234
Scott Ritchie Avatar asked Nov 05 '13 00:11

Scott Ritchie


2 Answers

The smallest normalised is double.xmin, as described in this page. The Wikipedia entry is very interesting and has the subnormal limit which is 2^-1074, which is approximately 4.9406564584124654 x 10^-324 (from Wikipedia as Ben Bolker mentioned in the comments). Your output in R is matching this value.

double.epsilon is not what you think. It is the smallest number you can add to 1 such as you obtain a number which will be not recognised as 1.

I suggest you read about how the double are stored in memory and the basics of double operations. Once you understand how a double is stored the lower limit is obvious.

like image 176
BlueTrin Avatar answered Nov 19 '22 16:11

BlueTrin


The accepted answer remains correct for base R, but using the package Rmpfr enables arbitrary precision. Example:

First, note issue in base R:

> p <- c("5e-600","2e-324","3e-324","4e-324", "5e-324","6e-324","7.1e-324","8e-324")
> as.numeric(p)
[1]  0.000000e+00  0.000000e+00 4.940656e-324 4.940656e-324 4.940656e-324 4.940656e-324
[7] 4.940656e-324 9.881313e-324

Observe that as we near the limit the precision is an issue and all values are 4.940656e-324.

Now use mpfr function from 'Rmpfr` package to cast the strings as floats:

> library(Rmpfr)
> .N <- function(.) mpfr(., precBits = 20)
> .N(p)
8 'mpfr' numbers of precision  20   bits 
[1] 5.0000007e-600   2.00000e-324 2.9999979e-324   4.00000e-324 4.9999966e-324 5.9999959e-324
[7]   7.09999e-324   8.00000e-324
like image 45
Vince Avatar answered Nov 19 '22 14:11

Vince