Home > database >  How to deal with underflow in R?
How to deal with underflow in R?

Time:10-31

I want to compute this number : 0.34911191 ^ 1157 I am using R programming language and it returns me 0 (this is an underflow problem). How I can fix it? Thanks.

CodePudding user response:

You can test the result using the Numerical Characteristics of the Machine (.Machine {base}), as shown below:

> 0.34911191 ^ 10 < .Machine$double.neg.eps
[1] FALSE
> 0.34911191 ^ 1157 < .Machine$double.neg.eps
[1] TRUE

double.neg.eps is a small positive floating-point number x such that 1 - x != 1.

CodePudding user response:

Are you looking for something like this?
The CRAN package Brobdingnag has two vignettes explaining its use.

library(Brobdingnag)

x <- 1157 * log(0.34911191)
y <- as.brob(x)
exp(y)
#[1]  exp(-1217.6)
exp(y) < .Machine$double.neg.eps
#[1] TRUE
  • Related