\frac{e^{x} - 1}{x}\begin{array}{l}
\mathbf{if}\;\frac{e^{x} - 1}{x} \leq 0:\\
\;\;\;\;1 + x \cdot \left(0.5 + x \cdot \left(0.16666666666666666 + x \cdot 0.041666666666666664\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x}}{x} - \frac{1}{x}\\
\end{array}(FPCore (x) :precision binary64 (/ (- (exp x) 1.0) x))
(FPCore (x)
:precision binary64
(if (<= (/ (- (exp x) 1.0) x) 0.0)
(+
1.0
(* x (+ 0.5 (* x (+ 0.16666666666666666 (* x 0.041666666666666664))))))
(- (/ (exp x) x) (/ 1.0 x))))double code(double x) {
return (exp(x) - 1.0) / x;
}
double code(double x) {
double tmp;
if (((exp(x) - 1.0) / x) <= 0.0) {
tmp = 1.0 + (x * (0.5 + (x * (0.16666666666666666 + (x * 0.041666666666666664)))));
} else {
tmp = (exp(x) / x) - (1.0 / x);
}
return tmp;
}




Bits error versus x
Results
| Original | 39.6 |
|---|---|
| Target | 40.1 |
| Herbie | 0.5 |
if (/.f64 (-.f64 (exp.f64 x) 1) x) < 0.0Initial program 62.0
Taylor expanded around 0 0
Simplified0
if 0.0 < (/.f64 (-.f64 (exp.f64 x) 1) x) Initial program 2.1
rmApplied div-sub_binary64_17411.4
Final simplification0.5
herbie shell --seed 2021042
(FPCore (x)
:name "Kahan's exp quotient"
:precision binary64
:herbie-target
(if (and (< x 1.0) (> x -1.0)) (/ (- (exp x) 1.0) (log (exp x))) (/ (- (exp x) 1.0) x))
(/ (- (exp x) 1.0) x))