\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.0000000104292335:\\
\;\;\;\;\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 r49035 = 1.0;
double r49036 = x;
double r49037 = r49035 + r49036;
double r49038 = log(r49037);
return r49038;
}
double f(double x) {
double r49039 = 1.0;
double r49040 = x;
double r49041 = r49039 + r49040;
double r49042 = 1.0000000104292335;
bool r49043 = r49041 <= r49042;
double r49044 = log(r49039);
double r49045 = 0.5;
double r49046 = 2.0;
double r49047 = pow(r49040, r49046);
double r49048 = pow(r49039, r49046);
double r49049 = r49047 / r49048;
double r49050 = r49045 * r49049;
double r49051 = r49044 - r49050;
double r49052 = fma(r49040, r49039, r49051);
double r49053 = log(r49041);
double r49054 = r49043 ? r49052 : r49053;
return r49054;
}




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