Closed WarrenWeckesser closed 2 years ago
The subtraction 1 - p in the formula 1 - (1 - p) ^ x loses precision when p is small. The mathematically equivalent expression -expm1(log1p(-p)*x) avoids the loss of precision.
1 - p
1 - (1 - p) ^ x
p
-expm1(log1p(-p)*x)
Thanks!
The subtraction
1 - p
in the formula1 - (1 - p) ^ x
loses precision whenp
is small. The mathematically equivalent expression-expm1(log1p(-p)*x)
avoids the loss of precision.