\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;x \le 6.021258785653700376368051283559879038876 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{2} \cdot \frac{x}{1}, \frac{x}{1}, \mathsf{fma}\left(1, x, \log 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(x + 1\right)\\
\end{array}double f(double x) {
double r2397273 = 1.0;
double r2397274 = x;
double r2397275 = r2397273 + r2397274;
double r2397276 = log(r2397275);
return r2397276;
}
double f(double x) {
double r2397277 = x;
double r2397278 = 6.0212587856537e-06;
bool r2397279 = r2397277 <= r2397278;
double r2397280 = -0.5;
double r2397281 = 1.0;
double r2397282 = r2397277 / r2397281;
double r2397283 = r2397280 * r2397282;
double r2397284 = log(r2397281);
double r2397285 = fma(r2397281, r2397277, r2397284);
double r2397286 = fma(r2397283, r2397282, r2397285);
double r2397287 = r2397277 + r2397281;
double r2397288 = log(r2397287);
double r2397289 = r2397279 ? r2397286 : r2397288;
return r2397289;
}




Bits error versus x
| Original | 39.3 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if x < 6.0212587856537e-06Initial program 59.1
Taylor expanded around 0 0.3
Simplified0.3
if 6.0212587856537e-06 < x Initial program 0.1
rmApplied add-log-exp0.1
Simplified0.1
Final simplification0.3
herbie shell --seed 2019172 +o rules:numerics
(FPCore (x)
:name "ln(1 + x)"
:herbie-target
(if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))
(log (+ 1.0 x)))