Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Holding On Near Zero (BigFloat)

expm1 is exp(x) - 1 and log1p is ln(1 + x), and both exist because the expressions they are named after throw their answers away for a small argument. exp(2^-100) rounds to one, so the difference is nought where the answer is 2^-100; 1 + 2^-100 rounds to one, so the logarithm is nought too. These two compute the difference and the logarithm directly:

from decimo.bigfloat.exponential import expm1, log1p

var tiny = BigFloat.power_of_two(-100000)
print(expm1(tiny, 53).internal_representation())   # 2^-100000, not nought
print(log1p(tiny, 53).internal_representation())   # and a hair under it

They are also what the hyperbolic functions are built on, which is why sinh(2^-100000) is 2^-100000 rather than zero.