Opens in a new tab
A picture of Jeff Brigman
I CODE TODAY FOR
A BETTER TOMORROW

Glossary Term

Math.expm1()

2 tags 1 category

The Math.expm1() static method returns e raised to the power of a number, subtracted by 1. That is

𝙼𝚊𝚝𝚑.𝚎𝚡𝚙𝚖𝟷(𝚡)=ex−1mathtt{operatorname{Math.expm1}(x)} = mathrm{e}^x – 1

For very small values of x, adding 1 can reduce or eliminate precision. The double floats used in JS give you about 15 digits of precision. 1 + 1e-15 = 1.000000000000001, but 1 + 1e-16 = 1.000000000000000 and therefore exactly 1.0 in that arithmetic, because digits past 15 are rounded off.

When you calculate exmathrm{e}^x, where x is a number very close to 0, you should get an answer very close to 1 + x because: limx→0ex−1x=1lim_{x to 0} frac{mathrm{e}^x – 1}{x} = 1. If you calculate Math.exp(1.1111111111e-15) – 1, you should get an answer close to 1.1111111111e-15. Instead, due to the highest significant figure in the result of Math.exp being the units digit 1, the final value ends up being 1.1102230246251565e-15, with only 3 correct digits. If you calculate Math.expm1(1.1111111111e-15) instead, you will get a much more accurate answer, 1.1111111111000007e-15, with 11 correct digits of precision.

Syntax example: Math.expm1(x)

Term Connections

Explore related terms connected by shared tags, shared categories, and relationship phrases. This map loads only when it comes into view.

Loading term connections…