100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
t_0 := 100 \cdot \frac{n}{\frac{i}{\mathsf{expm1}\left(i\right)}}\\
\mathbf{if}\;n \leq -1.8422714442376505 \cdot 10^{-192}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;n \leq -5.21080278599253 \cdot 10^{-310}:\\
\;\;\;\;100 \cdot \frac{\mathsf{expm1}\left(n \cdot \log \left(1 + \frac{i}{n}\right)\right)}{\frac{i}{n}}\\
\mathbf{elif}\;n \leq 1.1323542808442225 \cdot 10^{-164}:\\
\;\;\;\;100 \cdot \frac{n \cdot \left(\log i - \log n\right)}{\frac{i}{n}}\\
\mathbf{elif}\;n \leq 0.0023543790910373224:\\
\;\;\;\;100 \cdot \frac{i}{\frac{i}{n}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
(FPCore (i n) :precision binary64 (* 100.0 (/ (- (pow (+ 1.0 (/ i n)) n) 1.0) (/ i n))))
(FPCore (i n)
:precision binary64
(let* ((t_0 (* 100.0 (/ n (/ i (expm1 i))))))
(if (<= n -1.8422714442376505e-192)
t_0
(if (<= n -5.21080278599253e-310)
(* 100.0 (/ (expm1 (* n (log (+ 1.0 (/ i n))))) (/ i n)))
(if (<= n 1.1323542808442225e-164)
(* 100.0 (/ (* n (- (log i) (log n))) (/ i n)))
(if (<= n 0.0023543790910373224) (* 100.0 (/ i (/ i n))) t_0))))))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 t_0 = 100.0 * (n / (i / expm1(i)));
double tmp;
if (n <= -1.8422714442376505e-192) {
tmp = t_0;
} else if (n <= -5.21080278599253e-310) {
tmp = 100.0 * (expm1(n * log(1.0 + (i / n))) / (i / n));
} else if (n <= 1.1323542808442225e-164) {
tmp = 100.0 * ((n * (log(i) - log(n))) / (i / n));
} else if (n <= 0.0023543790910373224) {
tmp = 100.0 * (i / (i / n));
} else {
tmp = t_0;
}
return tmp;
}




Bits error versus i




Bits error versus n
Results
| Original | 47.7 |
|---|---|
| Target | 47.3 |
| Herbie | 11.4 |
if n < -1.84227144423765048e-192 or 0.00235437909103732241 < n Initial program 50.6
Taylor expanded in n around inf 46.9
Simplified11.7
Applied associate-/l*_binary649.0
if -1.84227144423765048e-192 < n < -5.21080278599253e-310Initial program 16.0
Applied pow-to-exp_binary6416.0
Applied expm1-def_binary649.7
if -5.21080278599253e-310 < n < 1.1323542808442225e-164Initial program 41.5
Taylor expanded in n around 0 14.1
if 1.1323542808442225e-164 < n < 0.00235437909103732241Initial program 54.9
Taylor expanded in i around 0 23.0
Final simplification11.4
herbie shell --seed 2022067
(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))))