100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;i \le -0.9131486383075666513065016260952688753605:\\
\;\;\;\;100 \cdot \frac{{\left(\frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\
\mathbf{elif}\;i \le 0.1038740591284738334909576451536850072443:\\
\;\;\;\;100 \cdot \left(\frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(0.5, {i}^{2}, \log 1 \cdot n\right)\right) - 0.5 \cdot \left({i}^{2} \cdot \log 1\right)}{i} \cdot n\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{100}{i} \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{1}{n}}\\
\end{array}double f(double i, double n) {
double r104209 = 100.0;
double r104210 = 1.0;
double r104211 = i;
double r104212 = n;
double r104213 = r104211 / r104212;
double r104214 = r104210 + r104213;
double r104215 = pow(r104214, r104212);
double r104216 = r104215 - r104210;
double r104217 = r104216 / r104213;
double r104218 = r104209 * r104217;
return r104218;
}
double f(double i, double n) {
double r104219 = i;
double r104220 = -0.9131486383075667;
bool r104221 = r104219 <= r104220;
double r104222 = 100.0;
double r104223 = n;
double r104224 = r104219 / r104223;
double r104225 = pow(r104224, r104223);
double r104226 = 1.0;
double r104227 = r104225 - r104226;
double r104228 = r104227 / r104224;
double r104229 = r104222 * r104228;
double r104230 = 0.10387405912847383;
bool r104231 = r104219 <= r104230;
double r104232 = 0.5;
double r104233 = 2.0;
double r104234 = pow(r104219, r104233);
double r104235 = log(r104226);
double r104236 = r104235 * r104223;
double r104237 = fma(r104232, r104234, r104236);
double r104238 = fma(r104226, r104219, r104237);
double r104239 = r104234 * r104235;
double r104240 = r104232 * r104239;
double r104241 = r104238 - r104240;
double r104242 = r104241 / r104219;
double r104243 = r104242 * r104223;
double r104244 = r104222 * r104243;
double r104245 = r104222 / r104219;
double r104246 = r104226 + r104224;
double r104247 = pow(r104246, r104223);
double r104248 = r104247 - r104226;
double r104249 = 1.0;
double r104250 = r104249 / r104223;
double r104251 = r104248 / r104250;
double r104252 = r104245 * r104251;
double r104253 = r104231 ? r104244 : r104252;
double r104254 = r104221 ? r104229 : r104253;
return r104254;
}




Bits error versus i




Bits error versus n
| Original | 43.1 |
|---|---|
| Target | 43.0 |
| Herbie | 19.2 |
if i < -0.9131486383075667Initial program 28.1
Taylor expanded around inf 64.0
Simplified18.7
if -0.9131486383075667 < i < 0.10387405912847383Initial program 50.8
Taylor expanded around 0 33.3
Simplified33.3
rmApplied associate-/r/16.4
if 0.10387405912847383 < i Initial program 32.5
rmApplied div-inv32.5
Applied *-un-lft-identity32.5
Applied times-frac32.6
Applied associate-*r*32.6
Simplified32.5
Final simplification19.2
herbie shell --seed 2019304 +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))))