\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000959807234:\\
\;\;\;\;\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 f(double x) {
double r81436 = 1.0;
double r81437 = x;
double r81438 = r81436 + r81437;
double r81439 = log(r81438);
return r81439;
}
double f(double x) {
double r81440 = 1.0;
double r81441 = x;
double r81442 = r81440 + r81441;
double r81443 = 1.0000000959807234;
bool r81444 = r81442 <= r81443;
double r81445 = log(r81440);
double r81446 = 0.5;
double r81447 = 2.0;
double r81448 = pow(r81441, r81447);
double r81449 = pow(r81440, r81447);
double r81450 = r81448 / r81449;
double r81451 = r81446 * r81450;
double r81452 = r81445 - r81451;
double r81453 = fma(r81441, r81440, r81452);
double r81454 = log(r81442);
double r81455 = r81444 ? r81453 : r81454;
return r81455;
}




Bits error versus x
| Original | 38.8 |
|---|---|
| Target | 0.3 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.0000000959807234Initial program 59.2
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000000959807234 < (+ 1.0 x) Initial program 0.2
Final simplification0.3
herbie shell --seed 2020064 +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)))