\frac{e^{x}}{e^{x} - 1}\begin{array}{l}
\mathbf{if}\;e^{x} \le 0.998767318263258708:\\
\;\;\;\;\frac{e^{x}}{\mathsf{fma}\left(-1, 1, e^{x + x}\right)} \cdot \left(e^{x} + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{1}{12}, x, \frac{1}{x}\right) + \frac{1}{2}\\
\end{array}double code(double x) {
return (exp(x) / (exp(x) - 1.0));
}
double code(double x) {
double temp;
if ((exp(x) <= 0.9987673182632587)) {
temp = ((exp(x) / fma(-1.0, 1.0, exp((x + x)))) * (exp(x) + 1.0));
} else {
temp = (fma(0.08333333333333333, x, (1.0 / x)) + 0.5);
}
return temp;
}




Bits error versus x
Results
| Original | 41.2 |
|---|---|
| Target | 40.8 |
| Herbie | 0.6 |
if (exp x) < 0.9987673182632587Initial program 0.0
rmApplied flip--0.0
Applied associate-/r/0.0
Simplified0.0
if 0.9987673182632587 < (exp x) Initial program 61.9
Taylor expanded around 0 0.9
Simplified0.9
Final simplification0.6
herbie shell --seed 2020057 +o rules:numerics
(FPCore (x)
:name "expq2 (section 3.11)"
:precision binary64
:herbie-target
(/ 1 (- 1 (exp (- x))))
(/ (exp x) (- (exp x) 1)))