\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000000133302457960837728023761883378:\\
\;\;\;\;\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 r76382 = 1.0;
double r76383 = x;
double r76384 = r76382 + r76383;
double r76385 = log(r76384);
return r76385;
}
double f(double x) {
double r76386 = 1.0;
double r76387 = x;
double r76388 = r76386 + r76387;
double r76389 = 1.0000000013330246;
bool r76390 = r76388 <= r76389;
double r76391 = log(r76386);
double r76392 = 0.5;
double r76393 = 2.0;
double r76394 = pow(r76387, r76393);
double r76395 = pow(r76386, r76393);
double r76396 = r76394 / r76395;
double r76397 = r76392 * r76396;
double r76398 = r76391 - r76397;
double r76399 = fma(r76387, r76386, r76398);
double r76400 = log(r76388);
double r76401 = r76390 ? r76399 : r76400;
return r76401;
}




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