\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000482441602:\\
\;\;\;\;\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 r117531 = 1.0;
double r117532 = x;
double r117533 = r117531 + r117532;
double r117534 = log(r117533);
return r117534;
}
double f(double x) {
double r117535 = 1.0;
double r117536 = x;
double r117537 = r117535 + r117536;
double r117538 = 1.0000000482441602;
bool r117539 = r117537 <= r117538;
double r117540 = log(r117535);
double r117541 = 0.5;
double r117542 = 2.0;
double r117543 = pow(r117536, r117542);
double r117544 = pow(r117535, r117542);
double r117545 = r117543 / r117544;
double r117546 = r117541 * r117545;
double r117547 = r117540 - r117546;
double r117548 = fma(r117536, r117535, r117547);
double r117549 = log(r117537);
double r117550 = r117539 ? r117548 : r117549;
return r117550;
}




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