100 \cdot \frac{{\left(1 + \frac{i}{n}\right)}^{n} - 1}{\frac{i}{n}}
\begin{array}{l}
\mathbf{if}\;i \leq -6.23013280765247 \cdot 10^{-16}:\\
\;\;\;\;n \cdot \frac{\mathsf{fma}\left(100, e^{n \cdot \mathsf{log1p}\left(\frac{i}{n}\right)}, -100\right)}{i}\\
\mathbf{elif}\;i \leq 0.057649679874463414:\\
\;\;\;\;\mathsf{fma}\left(16.666666666666668, n \cdot \left(i \cdot i\right), \mathsf{fma}\left(100, n, \mathsf{fma}\left(33.333333333333336, i \cdot \frac{i}{n}, 50 \cdot \left(i \cdot n\right)\right)\right)\right) - 50 \cdot \left(i + i \cdot i\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{100 \cdot \left(n \cdot \mathsf{expm1}\left(n \cdot \mathsf{fma}\left(-1, \log n, \log i\right)\right)\right)}{i}\\
\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 -6.23013280765247e-16)
(* n (/ (fma 100.0 (exp (* n (log1p (/ i n)))) -100.0) i))
(if (<= i 0.057649679874463414)
(-
(fma
16.666666666666668
(* n (* i i))
(fma 100.0 n (fma 33.333333333333336 (* i (/ i n)) (* 50.0 (* i n)))))
(* 50.0 (+ i (* i i))))
(/ (* 100.0 (* n (expm1 (* n (fma -1.0 (log n) (log i)))))) i))))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 <= -6.23013280765247e-16) {
tmp = n * (fma(100.0, exp(n * log1p(i / n)), -100.0) / i);
} else if (i <= 0.057649679874463414) {
tmp = fma(16.666666666666668, (n * (i * i)), fma(100.0, n, fma(33.333333333333336, (i * (i / n)), (50.0 * (i * n))))) - (50.0 * (i + (i * i)));
} else {
tmp = (100.0 * (n * expm1(n * fma(-1.0, log(n), log(i))))) / i;
}
return tmp;
}




Bits error versus i




Bits error versus n
| Original | 47.2 |
|---|---|
| Target | 47.5 |
| Herbie | 10.3 |
if i < -6.2301328076524699e-16Initial program 29.0
Simplified29.6
Applied pow-to-exp_binary6429.6
Simplified7.2
if -6.2301328076524699e-16 < i < 0.057649679874463414Initial program 58.2
Simplified57.8
Taylor expanded in i around 0 9.2
Simplified9.2
Applied *-un-lft-identity_binary649.2
Applied times-frac_binary649.1
if 0.057649679874463414 < i Initial program 30.9
Simplified30.9
Taylor expanded in i around inf 30.1
Simplified21.4
Final simplification10.3
herbie shell --seed 2022081
(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))))