\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.00000202420025896543620547163300216198:\\
\;\;\;\;\mathsf{fma}\left(1, x, \log 1\right) - \frac{1}{2} \cdot \frac{{x}^{2}}{{1}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}double f(double x) {
double r64819 = 1.0;
double r64820 = x;
double r64821 = r64819 + r64820;
double r64822 = log(r64821);
return r64822;
}
double f(double x) {
double r64823 = 1.0;
double r64824 = x;
double r64825 = r64823 + r64824;
double r64826 = 1.000002024200259;
bool r64827 = r64825 <= r64826;
double r64828 = log(r64823);
double r64829 = fma(r64823, r64824, r64828);
double r64830 = 0.5;
double r64831 = 2.0;
double r64832 = pow(r64824, r64831);
double r64833 = pow(r64823, r64831);
double r64834 = r64832 / r64833;
double r64835 = r64830 * r64834;
double r64836 = r64829 - r64835;
double r64837 = log(r64825);
double r64838 = r64827 ? r64836 : r64837;
return r64838;
}




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