100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -2.7755718047646672 \cdot 10^{-12}:\\
\;\;\;\;\frac{\mathsf{fma}\left(100, e^{\mathsf{log1p}\left(\frac{i}{n}\right) \cdot n}, -100\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 4.5457902375689345:\\
\;\;\;\;\mathsf{fma}\left(i, 50 \cdot n, n \cdot \mathsf{fma}\left(i \cdot i, \frac{50}{3}, 100\right)\right)\\
\mathbf{else}:\\
\;\;\;\;n \cdot \frac{\mathsf{fma}\left(100, {\left(\frac{i}{n} + 1\right)}^{n}, -100\right)}{i}\\
\end{array}double f(double i, double n) {
double r1785058 = 100.0;
double r1785059 = 1.0;
double r1785060 = i;
double r1785061 = n;
double r1785062 = r1785060 / r1785061;
double r1785063 = r1785059 + r1785062;
double r1785064 = pow(r1785063, r1785061);
double r1785065 = r1785064 - r1785059;
double r1785066 = r1785065 / r1785062;
double r1785067 = r1785058 * r1785066;
return r1785067;
}
double f(double i, double n) {
double r1785068 = i;
double r1785069 = -2.7755718047646672e-12;
bool r1785070 = r1785068 <= r1785069;
double r1785071 = 100.0;
double r1785072 = n;
double r1785073 = r1785068 / r1785072;
double r1785074 = log1p(r1785073);
double r1785075 = r1785074 * r1785072;
double r1785076 = exp(r1785075);
double r1785077 = -100.0;
double r1785078 = fma(r1785071, r1785076, r1785077);
double r1785079 = r1785078 / r1785073;
double r1785080 = 4.5457902375689345;
bool r1785081 = r1785068 <= r1785080;
double r1785082 = 50.0;
double r1785083 = r1785082 * r1785072;
double r1785084 = r1785068 * r1785068;
double r1785085 = 16.666666666666668;
double r1785086 = fma(r1785084, r1785085, r1785071);
double r1785087 = r1785072 * r1785086;
double r1785088 = fma(r1785068, r1785083, r1785087);
double r1785089 = 1.0;
double r1785090 = r1785073 + r1785089;
double r1785091 = pow(r1785090, r1785072);
double r1785092 = fma(r1785071, r1785091, r1785077);
double r1785093 = r1785092 / r1785068;
double r1785094 = r1785072 * r1785093;
double r1785095 = r1785081 ? r1785088 : r1785094;
double r1785096 = r1785070 ? r1785079 : r1785095;
return r1785096;
}




Bits error versus i




Bits error versus n
| Original | 42.0 |
|---|---|
| Target | 42.3 |
| Herbie | 16.2 |
if i < -2.7755718047646672e-12Initial program 27.8
Simplified27.8
rmApplied add-exp-log27.8
Simplified6.6
if -2.7755718047646672e-12 < i < 4.5457902375689345Initial program 50.1
Simplified50.1
Taylor expanded around 0 33.1
Simplified33.1
Taylor expanded around inf 16.8
Simplified16.8
if 4.5457902375689345 < i Initial program 31.0
Simplified31.0
rmApplied associate-/r/31.0
Final simplification16.2
herbie shell --seed 2019152 +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))))