100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\begin{array}{l}
\mathbf{if}\;n \le -1.8403630755190044 \cdot 10^{260}:\\
\;\;\;\;\frac{\frac{100 \cdot \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)}{i}}{\frac{1}{n}}\\
\mathbf{elif}\;n \le 1.2344778126423281 \cdot 10^{-267}:\\
\;\;\;\;\frac{100}{i} \cdot \left({\left(1 + \frac{i}{n}\right)}^{n} \cdot n - 1 \cdot n\right)\\
\mathbf{elif}\;n \le 4.27971623982010377 \cdot 10^{-165}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(1, i, \mathsf{fma}\left(\log 1, n, 1\right)\right) - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;\frac{100 \cdot \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)}{i} \cdot n\\
\end{array}double f(double i, double n) {
double r147178 = 100.0;
double r147179 = 1.0;
double r147180 = i;
double r147181 = n;
double r147182 = r147180 / r147181;
double r147183 = r147179 + r147182;
double r147184 = pow(r147183, r147181);
double r147185 = r147184 - r147179;
double r147186 = r147185 / r147182;
double r147187 = r147178 * r147186;
return r147187;
}
double f(double i, double n) {
double r147188 = n;
double r147189 = -1.8403630755190044e+260;
bool r147190 = r147188 <= r147189;
double r147191 = 100.0;
double r147192 = i;
double r147193 = 1.0;
double r147194 = 0.5;
double r147195 = 2.0;
double r147196 = pow(r147192, r147195);
double r147197 = log(r147193);
double r147198 = r147197 * r147188;
double r147199 = fma(r147194, r147196, r147198);
double r147200 = r147196 * r147197;
double r147201 = r147194 * r147200;
double r147202 = r147199 - r147201;
double r147203 = fma(r147192, r147193, r147202);
double r147204 = r147191 * r147203;
double r147205 = r147204 / r147192;
double r147206 = 1.0;
double r147207 = r147206 / r147188;
double r147208 = r147205 / r147207;
double r147209 = 1.234477812642328e-267;
bool r147210 = r147188 <= r147209;
double r147211 = r147191 / r147192;
double r147212 = r147192 / r147188;
double r147213 = r147193 + r147212;
double r147214 = pow(r147213, r147188);
double r147215 = r147214 * r147188;
double r147216 = r147193 * r147188;
double r147217 = r147215 - r147216;
double r147218 = r147211 * r147217;
double r147219 = 4.279716239820104e-165;
bool r147220 = r147188 <= r147219;
double r147221 = fma(r147197, r147188, r147206);
double r147222 = fma(r147193, r147192, r147221);
double r147223 = r147222 - r147193;
double r147224 = r147223 / r147212;
double r147225 = r147191 * r147224;
double r147226 = r147205 * r147188;
double r147227 = r147220 ? r147225 : r147226;
double r147228 = r147210 ? r147218 : r147227;
double r147229 = r147190 ? r147208 : r147228;
return r147229;
}




Bits error versus i




Bits error versus n
| Original | 41.1 |
|---|---|
| Target | 40.9 |
| Herbie | 24.6 |
if n < -1.8403630755190044e+260Initial program 56.0
rmApplied div-inv56.1
Applied *-un-lft-identity56.1
Applied times-frac55.6
Applied associate-*r*55.6
Simplified55.6
Taylor expanded around 0 37.0
Simplified37.0
rmApplied associate-*r/37.0
Simplified37.0
if -1.8403630755190044e+260 < n < 1.234477812642328e-267Initial program 26.1
rmApplied div-inv26.1
Applied *-un-lft-identity26.1
Applied times-frac26.3
Applied associate-*r*26.4
Simplified26.4
rmApplied div-sub26.4
Simplified29.0
Simplified26.4
if 1.234477812642328e-267 < n < 4.279716239820104e-165Initial program 42.2
Taylor expanded around 0 33.4
Simplified33.4
if 4.279716239820104e-165 < n Initial program 58.8
rmApplied div-inv58.8
Applied *-un-lft-identity58.8
Applied times-frac58.5
Applied associate-*r*58.5
Simplified58.5
Taylor expanded around 0 23.5
Simplified23.5
rmApplied associate-/r/23.4
Applied associate-*r*19.6
Simplified19.4
Final simplification24.6
herbie shell --seed 2020027 +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))))