100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -5.737712731949101 \cdot 10^{-05}:\\
\;\;\;\;\frac{1}{\frac{i}{n \cdot \mathsf{fma}\left(100, e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, -100\right)}}\\
\mathbf{elif}\;i \le 0.0004866774544189746:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\frac{i}{n}, \frac{\frac{1}{200}}{n}, \mathsf{fma}\left(\frac{i}{n}, \frac{-1}{200}, \frac{\frac{1}{100}}{n}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{100 \cdot {\left(1 + \frac{i}{n}\right)}^{n} + -100}{\frac{i}{n}}\\
\end{array}double f(double i, double n) {
double r5183450 = 100.0;
double r5183451 = 1.0;
double r5183452 = i;
double r5183453 = n;
double r5183454 = r5183452 / r5183453;
double r5183455 = r5183451 + r5183454;
double r5183456 = pow(r5183455, r5183453);
double r5183457 = r5183456 - r5183451;
double r5183458 = r5183457 / r5183454;
double r5183459 = r5183450 * r5183458;
return r5183459;
}
double f(double i, double n) {
double r5183460 = i;
double r5183461 = -5.737712731949101e-05;
bool r5183462 = r5183460 <= r5183461;
double r5183463 = 1.0;
double r5183464 = n;
double r5183465 = 100.0;
double r5183466 = r5183460 / r5183464;
double r5183467 = log1p(r5183466);
double r5183468 = r5183467 * r5183464;
double r5183469 = exp(r5183468);
double r5183470 = -100.0;
double r5183471 = fma(r5183465, r5183469, r5183470);
double r5183472 = r5183464 * r5183471;
double r5183473 = r5183460 / r5183472;
double r5183474 = r5183463 / r5183473;
double r5183475 = 0.0004866774544189746;
bool r5183476 = r5183460 <= r5183475;
double r5183477 = 0.005;
double r5183478 = r5183477 / r5183464;
double r5183479 = -0.005;
double r5183480 = 0.01;
double r5183481 = r5183480 / r5183464;
double r5183482 = fma(r5183466, r5183479, r5183481);
double r5183483 = fma(r5183466, r5183478, r5183482);
double r5183484 = r5183463 / r5183483;
double r5183485 = r5183463 + r5183466;
double r5183486 = pow(r5183485, r5183464);
double r5183487 = r5183465 * r5183486;
double r5183488 = r5183487 + r5183470;
double r5183489 = r5183488 / r5183466;
double r5183490 = r5183476 ? r5183484 : r5183489;
double r5183491 = r5183462 ? r5183474 : r5183490;
return r5183491;
}




Bits error versus i




Bits error versus n
| Original | 42.7 |
|---|---|
| Target | 42.2 |
| Herbie | 13.3 |
if i < -5.737712731949101e-05Initial program 29.1
Simplified29.1
rmApplied add-exp-log29.1
Applied pow-exp29.1
Simplified5.7
rmApplied clear-num5.8
rmApplied associate-/l/6.2
if -5.737712731949101e-05 < i < 0.0004866774544189746Initial program 50.1
Simplified50.1
rmApplied add-exp-log50.1
Applied pow-exp50.1
Simplified49.3
rmApplied clear-num49.3
Taylor expanded around 0 13.3
Simplified13.2
rmApplied clear-num13.2
Simplified11.9
if 0.0004866774544189746 < i Initial program 31.4
Simplified31.4
rmApplied fma-udef31.4
Final simplification13.3
herbie shell --seed 2019163 +o rules:numerics
(FPCore (i n)
:name "Compound Interest"
: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))))