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 r4868175 = 100.0;
double r4868176 = 1.0;
double r4868177 = i;
double r4868178 = n;
double r4868179 = r4868177 / r4868178;
double r4868180 = r4868176 + r4868179;
double r4868181 = pow(r4868180, r4868178);
double r4868182 = r4868181 - r4868176;
double r4868183 = r4868182 / r4868179;
double r4868184 = r4868175 * r4868183;
return r4868184;
}
double f(double i, double n) {
double r4868185 = i;
double r4868186 = -1.8795028361709332;
bool r4868187 = r4868185 <= r4868186;
double r4868188 = 100.0;
double r4868189 = n;
double r4868190 = r4868185 / r4868189;
double r4868191 = 1.0;
double r4868192 = r4868190 + r4868191;
double r4868193 = pow(r4868192, r4868189);
double r4868194 = r4868193 / r4868190;
double r4868195 = /* ERROR: no posit support in C */;
double r4868196 = /* ERROR: no posit support in C */;
double r4868197 = r4868191 / r4868190;
double r4868198 = r4868196 - r4868197;
double r4868199 = r4868188 * r4868198;
double r4868200 = 0.0004866774544189746;
bool r4868201 = r4868185 <= r4868200;
double r4868202 = 0.5;
double r4868203 = r4868189 * r4868202;
double r4868204 = r4868185 * r4868203;
double r4868205 = r4868189 + r4868204;
double r4868206 = 0.16666666666666666;
double r4868207 = r4868185 * r4868206;
double r4868208 = r4868185 * r4868207;
double r4868209 = r4868189 * r4868208;
double r4868210 = r4868205 + r4868209;
double r4868211 = r4868188 * r4868210;
double r4868212 = r4868193 / r4868185;
double r4868213 = r4868191 / r4868185;
double r4868214 = r4868212 - r4868213;
double r4868215 = r4868189 * r4868214;
double r4868216 = r4868215 * r4868188;
double r4868217 = r4868201 ? r4868211 : r4868216;
double r4868218 = r4868187 ? r4868199 : r4868217;
return r4868218;
}




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