100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -2.2717441078324636 \cdot 10^{-10}:\\
\;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)\\
\mathbf{elif}\;i \le 2.5704520336039343 \cdot 10^{-23}:\\
\;\;\;\;\left(100 \cdot \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}\right) \cdot n\\
\mathbf{elif}\;i \le 1.5471622621860444 \cdot 10^{204}:\\
\;\;\;\;100 \cdot \left(\frac{{\left(1 + \frac{i}{n}\right)}^{n}}{\frac{i}{n}} - \frac{1}{\frac{i}{n}}\right)\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\
\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 temp;
if ((i <= -2.2717441078324636e-10)) {
temp = (100.0 * ((pow((1.0 + (i / n)), n) / (i / n)) - (1.0 / (i / n))));
} else {
double temp_1;
if ((i <= 2.5704520336039343e-23)) {
temp_1 = ((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);
} else {
double temp_2;
if ((i <= 1.5471622621860444e+204)) {
temp_2 = (100.0 * ((pow((1.0 + (i / n)), n) / (i / n)) - (1.0 / (i / n))));
} else {
temp_2 = (100.0 * ((fma(1.0, i, fma(log(1.0), n, 1.0)) - 1.0) / (i / n)));
}
temp_1 = temp_2;
}
temp = temp_1;
}
return temp;
}




Bits error versus i




Bits error versus n
Results
| Original | 48.0 |
|---|---|
| Target | 48.1 |
| Herbie | 17.6 |
if i < -2.2717441078324636e-10 or 2.5704520336039343e-23 < i < 1.5471622621860444e+204Initial program 31.5
rmApplied div-sub31.5
if -2.2717441078324636e-10 < i < 2.5704520336039343e-23Initial program 58.5
Taylor expanded around 0 26.1
Simplified26.1
rmApplied associate-/r/8.5
Applied associate-*r*8.5
if 1.5471622621860444e+204 < i Initial program 33.2
Taylor expanded around 0 32.5
Simplified32.5
Final simplification17.6
herbie shell --seed 2020065 +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))))