100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -1.8795028361709332:\\
\;\;\;\;100 \cdot \left(\left(\left(\frac{{\left(\frac{i}{n} + 1\right)}^{n}}{\frac{i}{n}}\right)\right) - \frac{1}{\frac{i}{n}}\right)\\
\mathbf{elif}\;i \le 0.0004866774544189746:\\
\;\;\;\;100 \cdot \left(\left(n + \left(n \cdot i\right) \cdot \frac{1}{2}\right) + n \cdot \left(\frac{1}{6} \cdot \left(i \cdot i\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(n \cdot \left(\frac{{\left(\frac{i}{n} + 1\right)}^{n}}{i} - \frac{1}{i}\right)\right) \cdot 100\\
\end{array}double f(double i, double n) {
double r7017867 = 100.0;
double r7017868 = 1.0;
double r7017869 = i;
double r7017870 = n;
double r7017871 = r7017869 / r7017870;
double r7017872 = r7017868 + r7017871;
double r7017873 = pow(r7017872, r7017870);
double r7017874 = r7017873 - r7017868;
double r7017875 = r7017874 / r7017871;
double r7017876 = r7017867 * r7017875;
return r7017876;
}
double f(double i, double n) {
double r7017877 = i;
double r7017878 = -1.8795028361709332;
bool r7017879 = r7017877 <= r7017878;
double r7017880 = 100.0;
double r7017881 = n;
double r7017882 = r7017877 / r7017881;
double r7017883 = 1.0;
double r7017884 = r7017882 + r7017883;
double r7017885 = pow(r7017884, r7017881);
double r7017886 = r7017885 / r7017882;
double r7017887 = /* ERROR: no posit support in C */;
double r7017888 = /* ERROR: no posit support in C */;
double r7017889 = r7017883 / r7017882;
double r7017890 = r7017888 - r7017889;
double r7017891 = r7017880 * r7017890;
double r7017892 = 0.0004866774544189746;
bool r7017893 = r7017877 <= r7017892;
double r7017894 = r7017881 * r7017877;
double r7017895 = 0.5;
double r7017896 = r7017894 * r7017895;
double r7017897 = r7017881 + r7017896;
double r7017898 = 0.16666666666666666;
double r7017899 = r7017877 * r7017877;
double r7017900 = r7017898 * r7017899;
double r7017901 = r7017881 * r7017900;
double r7017902 = r7017897 + r7017901;
double r7017903 = r7017880 * r7017902;
double r7017904 = r7017885 / r7017877;
double r7017905 = r7017883 / r7017877;
double r7017906 = r7017904 - r7017905;
double r7017907 = r7017881 * r7017906;
double r7017908 = r7017907 * r7017880;
double r7017909 = r7017893 ? r7017903 : r7017908;
double r7017910 = r7017879 ? r7017891 : r7017909;
return r7017910;
}




Bits error versus i




Bits error versus n
| Original | 42.7 |
|---|---|
| Target | 42.2 |
| Herbie | 17.8 |
if i < -1.8795028361709332Initial program 28.6
rmApplied div-sub28.6
rmApplied insert-posit1612.7
if -1.8795028361709332 < i < 0.0004866774544189746Initial program 50.1
rmApplied div-sub50.1
Taylor expanded around 0 16.7
Simplified16.7
if 0.0004866774544189746 < i Initial program 31.4
rmApplied div-sub31.4
rmApplied associate-/r/34.4
Applied associate-/r/31.4
Applied distribute-rgt-out--31.4
Final simplification17.8
herbie shell --seed 2019163
(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))))