I have the problem that a sum of variables representing probabilities in the [0,1]
interval sum to 0
but should be >0
. The problem
R itself can only deal with 64 bit floating point numbers, the Rmpfr
package can deal with arbitrary precision floating point numbers:
library(Rmpfr)
> p1 = mpfr("0.8", 128)
> p2 = mpfr("0.9999999999999998", 128)
> p11 = p1 * p2
> p10 = p1 - p11
> p01 = p2 - p11
> p00 = 1 - p11 - p10 - p01
> p00
1 'mpfr' number of precision 128 bits
[1] 4.00000000000000000000000461461738779728e-17
Edit: Use stings to define mpfr