\log \left(1.0 + x\right)
\begin{array}{l}
\mathbf{if}\;x \le 4.018374793923451 \cdot 10^{-06}:\\
\;\;\;\;\mathsf{fma}\left(\frac{x}{1.0} \cdot \frac{x}{1.0}, \frac{-1}{2}, \mathsf{fma}\left(1.0, x, \log 1.0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1.0 + x\right)\\
\end{array}double f(double x) {
double r3328260 = 1.0;
double r3328261 = x;
double r3328262 = r3328260 + r3328261;
double r3328263 = log(r3328262);
return r3328263;
}
double f(double x) {
double r3328264 = x;
double r3328265 = 4.018374793923451e-06;
bool r3328266 = r3328264 <= r3328265;
double r3328267 = 1.0;
double r3328268 = r3328264 / r3328267;
double r3328269 = r3328268 * r3328268;
double r3328270 = -0.5;
double r3328271 = log(r3328267);
double r3328272 = fma(r3328267, r3328264, r3328271);
double r3328273 = fma(r3328269, r3328270, r3328272);
double r3328274 = r3328267 + r3328264;
double r3328275 = log(r3328274);
double r3328276 = r3328266 ? r3328273 : r3328275;
return r3328276;
}




Bits error versus x
| Original | 38.7 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if x < 4.018374793923451e-06Initial program 58.9
Taylor expanded around 0 0.4
Simplified0.4
if 4.018374793923451e-06 < x Initial program 0.1
rmApplied add-log-exp0.1
Simplified0.1
Final simplification0.3
herbie shell --seed 2019165 +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)))