You are using expm1(x) for anything close to 0. Positive or negative.
The reason is that exp(x) everything that is close to 0 will be very close to 1. Therefore, exp(x) - 1 will suffer from destructive cancellation if x close to 0.
expm1(x) correctly optimized to avoid this devastating failure.
On the mathematical side: if exp is implemented using its Taylor series, then expm1(x) can be done simply by omitting the first +1 .
source share