100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -2.56140166535216897 \cdot 10^{135}:\\
\;\;\;\;\frac{\frac{\log \left(e^{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} - 1 \cdot 1}\right) \cdot 100}{{\left(1 + \frac{i}{n}\right)}^{n} + 1}}{\frac{i}{n}}\\
\mathbf{elif}\;i \le -1.3992561866449662 \cdot 10^{-10}:\\
\;\;\;\;\frac{100 \cdot \left({\left(\frac{i}{n}\right)}^{n} - 1\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 2.51591290926460688 \cdot 10^{-160}:\\
\;\;\;\;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)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 6.02622510223326963 \cdot 10^{-125}:\\
\;\;\;\;\frac{1}{i} \cdot \left(\frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot \left(2 \cdot n\right)\right)} + \left(-\left(-1 \cdot 1\right) \cdot \left(-1 \cdot 1\right)\right)}{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + 1 \cdot 1} \cdot 100}{{\left(1 + \frac{i}{n}\right)}^{n} + 1} \cdot n\right)\\
\mathbf{elif}\;i \le 8532543483832934860000:\\
\;\;\;\;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)}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 7.39555913873958208 \cdot 10^{219}:\\
\;\;\;\;\frac{1}{i} \cdot \left(\frac{\frac{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot \left(2 \cdot n\right)\right)} + \left(-\left(-1 \cdot 1\right) \cdot \left(-1 \cdot 1\right)\right)}{{\left(1 + \frac{i}{n}\right)}^{\left(2 \cdot n\right)} + 1 \cdot 1} \cdot 100}{{\left(1 + \frac{i}{n}\right)}^{n} + 1} \cdot 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 f(double i, double n) {
double r328890 = 100.0;
double r328891 = 1.0;
double r328892 = i;
double r328893 = n;
double r328894 = r328892 / r328893;
double r328895 = r328891 + r328894;
double r328896 = pow(r328895, r328893);
double r328897 = r328896 - r328891;
double r328898 = r328897 / r328894;
double r328899 = r328890 * r328898;
return r328899;
}
double f(double i, double n) {
double r328900 = i;
double r328901 = -2.561401665352169e+135;
bool r328902 = r328900 <= r328901;
double r328903 = 1.0;
double r328904 = n;
double r328905 = r328900 / r328904;
double r328906 = r328903 + r328905;
double r328907 = 2.0;
double r328908 = r328907 * r328904;
double r328909 = pow(r328906, r328908);
double r328910 = r328903 * r328903;
double r328911 = r328909 - r328910;
double r328912 = exp(r328911);
double r328913 = log(r328912);
double r328914 = 100.0;
double r328915 = r328913 * r328914;
double r328916 = pow(r328906, r328904);
double r328917 = r328916 + r328903;
double r328918 = r328915 / r328917;
double r328919 = r328918 / r328905;
double r328920 = -1.3992561866449662e-10;
bool r328921 = r328900 <= r328920;
double r328922 = pow(r328905, r328904);
double r328923 = r328922 - r328903;
double r328924 = r328914 * r328923;
double r328925 = r328924 / r328905;
double r328926 = 2.515912909264607e-160;
bool r328927 = r328900 <= r328926;
double r328928 = 0.5;
double r328929 = pow(r328900, r328907);
double r328930 = log(r328903);
double r328931 = r328930 * r328904;
double r328932 = fma(r328928, r328929, r328931);
double r328933 = r328929 * r328930;
double r328934 = r328928 * r328933;
double r328935 = r328932 - r328934;
double r328936 = fma(r328900, r328903, r328935);
double r328937 = r328936 / r328905;
double r328938 = r328914 * r328937;
double r328939 = 6.02622510223327e-125;
bool r328940 = r328900 <= r328939;
double r328941 = 1.0;
double r328942 = r328941 / r328900;
double r328943 = r328907 * r328908;
double r328944 = pow(r328906, r328943);
double r328945 = -r328910;
double r328946 = r328945 * r328945;
double r328947 = -r328946;
double r328948 = r328944 + r328947;
double r328949 = r328909 + r328910;
double r328950 = r328948 / r328949;
double r328951 = r328950 * r328914;
double r328952 = r328951 / r328917;
double r328953 = r328952 * r328904;
double r328954 = r328942 * r328953;
double r328955 = 8.532543483832935e+21;
bool r328956 = r328900 <= r328955;
double r328957 = 7.395559138739582e+219;
bool r328958 = r328900 <= r328957;
double r328959 = fma(r328930, r328904, r328941);
double r328960 = fma(r328903, r328900, r328959);
double r328961 = r328960 - r328903;
double r328962 = r328961 / r328905;
double r328963 = r328914 * r328962;
double r328964 = r328958 ? r328954 : r328963;
double r328965 = r328956 ? r328938 : r328964;
double r328966 = r328940 ? r328954 : r328965;
double r328967 = r328927 ? r328938 : r328966;
double r328968 = r328921 ? r328925 : r328967;
double r328969 = r328902 ? r328919 : r328968;
return r328969;
}




Bits error versus i




Bits error versus n
| Original | 42.7 |
|---|---|
| Target | 42.6 |
| Herbie | 31.4 |
if i < -2.561401665352169e+135Initial program 15.4
rmApplied associate-*r/15.4
rmApplied flip--15.4
Applied associate-*r/15.4
Simplified15.4
rmApplied add-log-exp15.4
Applied neg-log15.4
Applied add-log-exp15.4
Applied sum-log15.4
Simplified15.4
if -2.561401665352169e+135 < i < -1.3992561866449662e-10Initial program 41.3
rmApplied associate-*r/41.3
Taylor expanded around inf 64.0
Simplified27.6
if -1.3992561866449662e-10 < i < 2.515912909264607e-160 or 6.02622510223327e-125 < i < 8.532543483832935e+21Initial program 49.9
Taylor expanded around 0 33.7
Simplified33.7
if 2.515912909264607e-160 < i < 6.02622510223327e-125 or 8.532543483832935e+21 < i < 7.395559138739582e+219Initial program 38.2
rmApplied associate-*r/38.1
rmApplied flip--38.1
Applied associate-*r/38.1
Simplified38.1
rmApplied flip-+38.2
Simplified38.1
Simplified38.1
rmApplied div-inv38.2
Applied *-un-lft-identity38.2
Applied times-frac38.1
Simplified38.1
if 7.395559138739582e+219 < i Initial program 30.6
Taylor expanded around 0 34.7
Simplified34.7
Final simplification31.4
herbie shell --seed 2020056 +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))))