100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq -3.9261148805468635:\\
\;\;\;\;100 \cdot \frac{e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)} - 1}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 339.51119695591177:\\
\;\;\;\;\frac{100 \cdot n}{\frac{i}{\mathsf{expm1}\left(i\right)}}\\
\mathbf{elif}\;i \leq 6.869232008206506 \cdot 10^{+129}:\\
\;\;\;\;100 \cdot \frac{\mathsf{fma}\left(0.5, \left(n \cdot n\right) \cdot {\log n}^{2}, \mathsf{fma}\left(n, \log i, \mathsf{fma}\left(0.5, \left(n \cdot n\right) \cdot {\log i}^{2}, \frac{n \cdot n}{i}\right)\right)\right) - \mathsf{fma}\left(n, \log n, \left(n \cdot n\right) \cdot \left(\log n \cdot \log i\right)\right)}{\frac{i}{n}}\\
\mathbf{elif}\;i \leq 5.028729354167085 \cdot 10^{+265}:\\
\;\;\;\;100 \cdot \left(n \cdot \frac{{\left(\frac{i}{n} + 1\right)}^{n} - 1}{i}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-100}{\mathsf{fma}\left(0.5, \frac{i}{n}, \frac{-1}{n}\right)}\\
\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 -3.9261148805468635)
(* 100.0 (/ (- (exp (* n (log1p (/ i n)))) 1.0) (/ i n)))
(if (<= i 339.51119695591177)
(/ (* 100.0 n) (/ i (expm1 i)))
(if (<= i 6.869232008206506e+129)
(*
100.0
(/
(-
(fma
0.5
(* (* n n) (pow (log n) 2.0))
(fma
n
(log i)
(fma 0.5 (* (* n n) (pow (log i) 2.0)) (/ (* n n) i))))
(fma n (log n) (* (* n n) (* (log n) (log i)))))
(/ i n)))
(if (<= i 5.028729354167085e+265)
(* 100.0 (* n (/ (- (pow (+ (/ i n) 1.0) n) 1.0) i)))
(/ -100.0 (fma 0.5 (/ i n) (/ -1.0 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 <= -3.9261148805468635) {
tmp = 100.0 * ((exp(n * log1p(i / n)) - 1.0) / (i / n));
} else if (i <= 339.51119695591177) {
tmp = (100.0 * n) / (i / expm1(i));
} else if (i <= 6.869232008206506e+129) {
tmp = 100.0 * ((fma(0.5, ((n * n) * pow(log(n), 2.0)), fma(n, log(i), fma(0.5, ((n * n) * pow(log(i), 2.0)), ((n * n) / i)))) - fma(n, log(n), ((n * n) * (log(n) * log(i))))) / (i / n));
} else if (i <= 5.028729354167085e+265) {
tmp = 100.0 * (n * ((pow(((i / n) + 1.0), n) - 1.0) / i));
} else {
tmp = -100.0 / fma(0.5, (i / n), (-1.0 / n));
}
return tmp;
}




Bits error versus i




Bits error versus n
| Original | 47.4 |
|---|---|
| Target | 46.8 |
| Herbie | 10.5 |
if i < -3.92611488054686353Initial program 27.8
Applied pow-to-exp_binary6427.8
Simplified5.6
if -3.92611488054686353 < i < 339.511196955911771Initial program 58.0
Taylor expanded in n around inf 56.6
Simplified14.8
Taylor expanded in i around -inf 56.7
Simplified15.0
Applied distribute-lft-neg-in_binary6415.0
Applied *-un-lft-identity_binary6415.0
Applied times-frac_binary649.7
Applied associate-/r*_binary649.7
Simplified9.6
if 339.511196955911771 < i < 6.8692320082065063e129Initial program 27.3
Taylor expanded in n around 0 9.4
Simplified9.4
if 6.8692320082065063e129 < i < 5.02872935416708484e265Initial program 33.1
Applied associate-/r/_binary6433.1
if 5.02872935416708484e265 < i Initial program 33.6
Taylor expanded in n around inf 64.0
Simplified64.0
Taylor expanded in i around -inf 64.0
Simplified64.0
Taylor expanded in i around 0 25.5
Simplified25.5
Final simplification10.5
herbie shell --seed 2021357
(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))))