\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000000521483745075101978727616369724:\\
\;\;\;\;\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 r73706 = 1.0;
double r73707 = x;
double r73708 = r73706 + r73707;
double r73709 = log(r73708);
return r73709;
}
double f(double x) {
double r73710 = 1.0;
double r73711 = x;
double r73712 = r73710 + r73711;
double r73713 = 1.0000000005214837;
bool r73714 = r73712 <= r73713;
double r73715 = log(r73710);
double r73716 = 0.5;
double r73717 = 2.0;
double r73718 = pow(r73711, r73717);
double r73719 = pow(r73710, r73717);
double r73720 = r73718 / r73719;
double r73721 = r73716 * r73720;
double r73722 = r73715 - r73721;
double r73723 = fma(r73711, r73710, r73722);
double r73724 = log(r73712);
double r73725 = r73714 ? r73723 : r73724;
return r73725;
}




Bits error versus x
| Original | 39.4 |
|---|---|
| Target | 0.2 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.0000000005214837Initial program 59.5
Taylor expanded around 0 0.2
Simplified0.2
if 1.0000000005214837 < (+ 1.0 x) Initial program 0.3
Final simplification0.3
herbie shell --seed 2020001 +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)))