100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq 346.1220968706167:\\
\;\;\;\;\left(n \cdot 100\right) \cdot \frac{\mathsf{expm1}\left(i\right)}{i}\\
\mathbf{elif}\;i \leq 5.111910710628546 \cdot 10^{+112}:\\
\;\;\;\;100 \cdot \frac{{n}^{2} \cdot \left(\log i - \log n\right)}{i}\\
\mathbf{elif}\;i \leq 8.043070052233076 \cdot 10^{+233}:\\
\;\;\;\;100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;100 \cdot \frac{0}{\frac{i}{n}}\\
\end{array}
(FPCore (i n) :precision binary64 (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))
(FPCore (i n)
:precision binary64
(if (<= i 346.1220968706167)
(* (* n 100.0) (/ (expm1 i) i))
(if (<= i 5.111910710628546e+112)
(* 100.0 (/ (* (pow n 2.0) (- (log i) (log n))) i))
(if (<= i 8.043070052233076e+233)
(* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n)))
(* 100.0 (/ 0.0 (/ i n)))))))double code(double i, double n) {
return 100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / (i / n));
}
double code(double i, double n) {
double tmp;
if (i <= 346.1220968706167) {
tmp = (n * 100.0) * (expm1(i) / i);
} else if (i <= 5.111910710628546e+112) {
tmp = 100.0 * ((pow(n, 2.0) * (log(i) - log(n))) / i);
} else if (i <= 8.043070052233076e+233) {
tmp = 100.0 * ((pow((1.0 + (i / n)), n) - 1.0) / (i / n));
} else {
tmp = 100.0 * (0.0 / (i / n));
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.6 |
|---|---|
| Target | 47.0 |
| Herbie | 12.0 |
if i < 346.1220968706167Initial program 50.3
Taylor expanded in n around inf 44.7
Simplified13.7
Applied *-un-lft-identity_binary6413.7
Applied times-frac_binary649.9
Applied associate-*r*_binary6410.0
Simplified10.0
if 346.1220968706167 < i < 5.1119107106285459e112Initial program 31.3
Taylor expanded in n around 0 8.8
if 5.1119107106285459e112 < i < 8.04307005223307566e233Initial program 29.6
if 8.04307005223307566e233 < i Initial program 33.5
Taylor expanded in i around 0 29.6
Final simplification12.0
herbie shell --seed 2021275
(FPCore (i n)
:name "Compound Interest"
:precision binary64
:herbie-target
(* 100.0 (/ (- (exp (* n (if (== (+ 1.0 (/ i n)) 1.0) (/ i n) (/ (* (/ i n) (log (+ 1.0 (/ i n)))) (- (+ (/ i n) 1.0) 1.0))))) 1.0) (/ i n)))
(* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))