> You’ll find F2XM1, which computes in a swoop (2𝑥−1) – a kind of pauper’s fused multiply-add, some twenty-five years ahead of its time.
No. It computes pow(2, x) - 1.
Suppose x is close to 0, so that pow(2, x) is close to 1, like 1.00000000000000002345678. Because of that leading 1 (to the left of the radix point), all those zeros also have to be stored, meaning some of the low-end digits will have to be dropped, so you end up rounding to 1.00000000000000002. But if you can subtract 1 from the exact result before rounding, then you can store more of the low-end digits: 2.345678e-18. Hence the F2XM1 instruction.
expm1 is the modern equivalent. That (plus the related log1p) are probably some of the most underutilized standard library math functions. They can substantially improve the accuracy of tons of calculations.
Can you give an example of a common situation where a programmer should have used expm1 or log1p but didn't? (the way it's common for people to test if something is inside/outside a circle or sphere by comparing the square root of the sum of squares to the radius as opposed to compare the sum of squares to the square of the radius, or use trig functions when linear algebra will do)
I do a reasonable amount of computational programming but to my recollection I've never used either of those functions.
One example I can think of is doing an interest calculation with small interest rates/short periods, where you'd want to know that someone owes you 0.000000001234 dollars in interest today rather than owing you 1.000000001 - 1 dollars.
One common situation is when evaluating CDFs for exponential or weibull probability distributions. The CDF formula for both of those distributions includes a 1 - e^(x) term that can easily be transformed into expm1 for additional precision.
No. It computes pow(2, x) - 1.
Suppose x is close to 0, so that pow(2, x) is close to 1, like 1.00000000000000002345678. Because of that leading 1 (to the left of the radix point), all those zeros also have to be stored, meaning some of the low-end digits will have to be dropped, so you end up rounding to 1.00000000000000002. But if you can subtract 1 from the exact result before rounding, then you can store more of the low-end digits: 2.345678e-18. Hence the F2XM1 instruction.