Calculate the exponentials of big negative value

r

Solution

Those number are too small. To know the minimum value your computer can handle try:

> .Machine$double.xmin
[1] 2.225074e-308

Will give you (from `?.Machine`)

the smallest non-zero normalized floating-point number, a power of the radix, i.e., double.base ^ double.min.exp. Normally 2.225074e-308.

In my case

> .Machine$double.base
[1] 2
> .Machine$double.min.exp
[1] -1022

Actually I can calculate powers up to

> exp(-745)

[1] 4.940656e-324

To go around this issue you need infinite precision arithmetic.

In R you can achieve that using package `Rmpfr` (PDF vignette)

library(Rmpfr)
# Calculate exp(-100)
> a <- mpfr(exp(-100), precBits=64)
# exp(-1000)
> a^10

1 'mpfr' number of precision  64   bits 
[1] 5.07595889754945890823e-435
# exp(-6400)

> a^64

1 'mpfr' number of precision  64   bits 
[1] 3.27578823787094497049e-2780
# use an array of powers

> ex <- c(10, 20, 50, 100, 500, 1000, 1e5)
> a ^ ex

7 'mpfr' numbers of precision  64   bits 
[1]     5.07595889754945890823e-435     2.57653587296115182772e-869
[3]    3.36969414830892462745e-2172    1.13548386531474089222e-4343
[5]   1.88757769782054893243e-21715   3.56294956530952353784e-43430
[7] 1.51693678090513840149e-4342945

Note that Rmpfr is based on GNU MPFR and requires GNU GMP. Under Linux you will need `gmp`, `gmp-devel`, `mpfr`, and `mpfr-devel` to be installed in your system in order to install these packages, not sure how that works under Windows.

Problem

I would like to know how can I get the exponential of big negative number in R? For example when I try : ``` > exp(-6400) [1] 0 > exp(-1200) [1] 0 > exp(-2000) [1] 0 ``` but I need the value of above expression, even if it is so small, how can I get it in R?

Original source