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 + i \cdot \left(n \cdot \frac{1}{2}\right)\right) + n \cdot \left(i \cdot \left(i \cdot \frac{1}{6}\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 r6429272 = 100.0;
double r6429273 = 1.0;
double r6429274 = i;
double r6429275 = n;
double r6429276 = r6429274 / r6429275;
double r6429277 = r6429273 + r6429276;
double r6429278 = pow(r6429277, r6429275);
double r6429279 = r6429278 - r6429273;
double r6429280 = r6429279 / r6429276;
double r6429281 = r6429272 * r6429280;
return r6429281;
}
double f(double i, double n) {
double r6429282 = i;
double r6429283 = -1.8795028361709332;
bool r6429284 = r6429282 <= r6429283;
double r6429285 = 100.0;
double r6429286 = n;
double r6429287 = r6429282 / r6429286;
double r6429288 = 1.0;
double r6429289 = r6429287 + r6429288;
double r6429290 = pow(r6429289, r6429286);
double r6429291 = r6429290 / r6429287;
double r6429292 = /* ERROR: no posit support in C */;
double r6429293 = /* ERROR: no posit support in C */;
double r6429294 = r6429288 / r6429287;
double r6429295 = r6429293 - r6429294;
double r6429296 = r6429285 * r6429295;
double r6429297 = 0.0004866774544189746;
bool r6429298 = r6429282 <= r6429297;
double r6429299 = 0.5;
double r6429300 = r6429286 * r6429299;
double r6429301 = r6429282 * r6429300;
double r6429302 = r6429286 + r6429301;
double r6429303 = 0.16666666666666666;
double r6429304 = r6429282 * r6429303;
double r6429305 = r6429282 * r6429304;
double r6429306 = r6429286 * r6429305;
double r6429307 = r6429302 + r6429306;
double r6429308 = r6429285 * r6429307;
double r6429309 = r6429290 / r6429282;
double r6429310 = r6429288 / r6429282;
double r6429311 = r6429309 - r6429310;
double r6429312 = r6429286 * r6429311;
double r6429313 = r6429312 * r6429285;
double r6429314 = r6429298 ? r6429308 : r6429313;
double r6429315 = r6429284 ? r6429296 : r6429314;
return r6429315;
}




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))))