100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq -3.81143365456763 \cdot 10^{+96}:\\
\;\;\;\;n \cdot \frac{\mathsf{fma}\left(100, {\left(\frac{i}{n}\right)}^{n}, -100\right)}{i}\\
\mathbf{elif}\;i \leq -8.204085708724183 \cdot 10^{-11}:\\
\;\;\;\;n \cdot \frac{\mathsf{fma}\left(100, e^{i}, -100\right)}{i}\\
\mathbf{elif}\;i \leq 0.585668199925356:\\
\;\;\;\;n \cdot 100\\
\mathbf{else}:\\
\;\;\;\;\log \left({\left(e^{100}\right)}^{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.81143365456763e+96)
(* n (/ (fma 100.0 (pow (/ i n) n) -100.0) i))
(if (<= i -8.204085708724183e-11)
(* n (/ (fma 100.0 (exp i) -100.0) i))
(if (<= i 0.585668199925356) (* n 100.0) (log (pow (exp 100.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.81143365456763e+96) {
tmp = n * (fma(100.0, pow((i / n), n), -100.0) / i);
} else if (i <= -8.204085708724183e-11) {
tmp = n * (fma(100.0, exp(i), -100.0) / i);
} else if (i <= 0.585668199925356) {
tmp = n * 100.0;
} else {
tmp = log(pow(exp(100.0), n));
}
return tmp;
}




Bits error versus i




Bits error versus n
| Original | 46.4 |
|---|---|
| Target | 42.3 |
| Herbie | 12.2 |
if i < -3.81143365456762995e96Initial program 19.6
Simplified20.2
Taylor expanded in i around inf 13.6
if -3.81143365456762995e96 < i < -8.20408570872418269e-11Initial program 44.1
Simplified44.7
Taylor expanded in n around inf 19.4
if -8.20408570872418269e-11 < i < 0.585668199925356014Initial program 58.4
Simplified58.1
Taylor expanded in i around 0 9.5
Taylor expanded in i around 0 9.4
if 0.585668199925356014 < i Initial program 33.5
Simplified33.4
Taylor expanded in i around 0 60.3
Applied div-inv_binary6460.3
Applied add-log-exp_binary6416.0
Simplified15.8
Final simplification12.2
herbie shell --seed 2022088
(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))))