\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \le 1.000000005155942339740704483119770884514:\\
\;\;\;\;\mathsf{fma}\left(\frac{-1}{2}, \frac{{x}^{2}}{{1}^{2}}, \mathsf{fma}\left(1, x, \log 1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}double f(double x) {
double r34946 = 1.0;
double r34947 = x;
double r34948 = r34946 + r34947;
double r34949 = log(r34948);
return r34949;
}
double f(double x) {
double r34950 = 1.0;
double r34951 = x;
double r34952 = r34950 + r34951;
double r34953 = 1.0000000051559423;
bool r34954 = r34952 <= r34953;
double r34955 = -0.5;
double r34956 = 2.0;
double r34957 = pow(r34951, r34956);
double r34958 = pow(r34950, r34956);
double r34959 = r34957 / r34958;
double r34960 = log(r34950);
double r34961 = fma(r34950, r34951, r34960);
double r34962 = fma(r34955, r34959, r34961);
double r34963 = log(r34952);
double r34964 = r34954 ? r34962 : r34963;
return r34964;
}




Bits error versus x
| Original | 38.7 |
|---|---|
| Target | 0.3 |
| Herbie | 0.3 |
if (+ 1.0 x) < 1.0000000051559423Initial program 59.2
rmApplied expm1-log1p-u59.2
Taylor expanded around 0 0.3
Simplified0.3
if 1.0000000051559423 < (+ 1.0 x) Initial program 0.3
Final simplification0.3
herbie shell --seed 2019322 +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)))