\log \left(1 + x\right)
\begin{array}{l}
\mathbf{if}\;1 + x \leq 1.0000335079842024:\\
\;\;\;\;x + \left(\left(x \cdot x\right) \cdot \left(x \cdot 0.3333333333333333 - 0.5\right) - 0.25 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(1 + x\right)\\
\end{array}(FPCore (x) :precision binary64 (log (+ 1.0 x)))
(FPCore (x) :precision binary64 (if (<= (+ 1.0 x) 1.0000335079842024) (+ x (- (* (* x x) (- (* x 0.3333333333333333) 0.5)) (* 0.25 (pow x 4.0)))) (log (+ 1.0 x))))
double code(double x) {
return log(1.0 + x);
}
double code(double x) {
double tmp;
if ((1.0 + x) <= 1.0000335079842024) {
tmp = x + (((x * x) * ((x * 0.3333333333333333) - 0.5)) - (0.25 * pow(x, 4.0)));
} else {
tmp = log(1.0 + x);
}
return tmp;
}




Bits error versus x
Results
| Original | 38.8 |
|---|---|
| Target | 0.2 |
| Herbie | 0.1 |
if (+.f64 1 x) < 1.0000335079842024Initial program 59.0
Taylor expanded around 0 0.1
Simplified0.1
if 1.0000335079842024 < (+.f64 1 x) Initial program 0.1
Final simplification0.1
herbie shell --seed 2021032
(FPCore (x)
:name "ln(1 + x)"
:precision binary64
:herbie-target
(if (== (+ 1.0 x) 1.0) x (/ (* x (log (+ 1.0 x))) (- (+ 1.0 x) 1.0)))
(log (+ 1.0 x)))