0

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.

michele
  • 17
  • 4
  • Nope, the packages Rmpfr and Ryacas don't work – michele Oct 30 '21 at 10:26
  • 1
    What does *"don't work"* mean? Can you describe the expected result? – Rui Barradas Oct 30 '21 at 12:24
  • It's unlikely that either of those packages has some issue that makes them fundamentally not work, and much more likely that something about _your implementation_ of them didn't work. Without any of your code, we don't know what that might be. That post also has 4 answers on it, not just the one that mentioned those 2 packages – camille Oct 30 '21 at 21:05

2 Answers2

0

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.

Halley Oliveira
  • 219
  • 2
  • 3
0

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
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66