\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000018915086017:\\
\;\;\;\;\mathsf{fma}\left(x, 1, \log 1 - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}double code(double x) {
return ((double) log(((double) (1.0 + x))));
}
double code(double x) {
double VAR;
if ((((double) (1.0 + x)) <= 1.0000018915086017)) {
VAR = ((double) fma(x, 1.0, ((double) (((double) log(1.0)) - ((double) (0.5 * ((double) (((double) pow(x, 2.0)) / ((double) pow(1.0, 2.0))))))))));
} else {
VAR = ((double) log(((double) (1.0 + x))));
}
return VAR;
}




Bits error versus x
Results
| Original | 39.1 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.0000018915086017Initial program 59.1
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000018915086017 < (+ 1.0 x) Initial program 0.1
Final simplification0.3
herbie shell --seed 2020123 +o rules:numerics
(FPCore (x)
:name "ln(1 + x)"
:precision binary64
:herbie-target
(if (== (+ 1 x) 1) x (/ (* x (log (+ 1 x))) (- (+ 1 x) 1)))
(log (+ 1 x)))