100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.0749921289443250955 \lor \neg \left(i \le 3.8426241943682245 \cdot 10^{22}\right):\\
\;\;\;\;\left(100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{i}\right) \cdot n\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \left(\frac{\mathsf{fma}\left(i, 1, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)\right)}{i} \cdot n\right)\\
\end{array}double code(double i, double n) {
return (100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / (i / n)));
}
double code(double i, double n) {
double VAR;
if (((i <= -0.0749921289443251) || !(i <= 3.8426241943682245e+22))) {
VAR = ((100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / i)) * n);
} else {
VAR = (100.0 * ((fma(i, 1.0, (fma(0.5, pow(i, 2.0), (log(1.0) * n)) - (0.5 * (pow(i, 2.0) * log(1.0))))) / i) * n));
}
return VAR;
}




Bits error versus i




Bits error versus n
Results
| Original | 48.2 |
|---|---|
| Target | 47.6 |
| Herbie | 17.1 |
if i < -0.0749921289443251 or 3.8426241943682245e+22 < i Initial program 30.0
rmApplied associate-/r/30.3
Applied associate-*r*30.3
if -0.0749921289443251 < i < 3.8426241943682245e+22Initial program 57.9
Taylor expanded around 0 27.0
Simplified27.0
rmApplied associate-/r/10.0
Final simplification17.1
herbie shell --seed 2020078 +o rules:numerics
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:herbie-target
(* 100 (/ (- (exp (* n (if (== (+ 1 (/ i n)) 1) (/ i n) (/ (* (/ i n) (log (+ 1 (/ i n)))) (- (+ (/ i n) 1) 1))))) 1) (/ i n)))
(* 100 (/ (- (pow (+ 1 (/ i n)) n) 1) (/ i n))))