\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000000143161:\\
\;\;\;\;\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 r77335 = 1.0;
double r77336 = x;
double r77337 = r77335 + r77336;
double r77338 = log(r77337);
return r77338;
}
double f(double x) {
double r77339 = 1.0;
double r77340 = x;
double r77341 = r77339 + r77340;
double r77342 = 1.000000000143161;
bool r77343 = r77341 <= r77342;
double r77344 = log(r77339);
double r77345 = 0.5;
double r77346 = 2.0;
double r77347 = pow(r77340, r77346);
double r77348 = pow(r77339, r77346);
double r77349 = r77347 / r77348;
double r77350 = r77345 * r77349;
double r77351 = r77344 - r77350;
double r77352 = fma(r77340, r77339, r77351);
double r77353 = log(r77341);
double r77354 = r77343 ? r77352 : r77353;
return r77354;
}




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