\log \left(\sqrt{re \cdot re + im \cdot im}\right)\begin{array}{l}
\mathbf{if}\;im \cdot im \leq 4.496931482573535 \cdot 10^{-289}:\\
\;\;\;\;\log \left(\left|re\right|\right)\\
\mathbf{elif}\;im \cdot im \leq 2.8151563237733957 \cdot 10^{-47}:\\
\;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\
\mathbf{elif}\;im \cdot im \leq 3.0416083611477998:\\
\;\;\;\;\log \left(\left|re\right|\right)\\
\mathbf{elif}\;im \cdot im \leq 1.1242704904966132 \cdot 10^{+233}:\\
\;\;\;\;\log \left(\sqrt{im \cdot im + re \cdot re}\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\left|im\right|\right)\\
\end{array}(FPCore (re im) :precision binary64 (log (sqrt (+ (* re re) (* im im)))))
(FPCore (re im)
:precision binary64
(if (<= (* im im) 4.496931482573535e-289)
(log (fabs re))
(if (<= (* im im) 2.8151563237733957e-47)
(log (sqrt (+ (* im im) (* re re))))
(if (<= (* im im) 3.0416083611477998)
(log (fabs re))
(if (<= (* im im) 1.1242704904966132e+233)
(log (sqrt (+ (* im im) (* re re))))
(log (fabs im)))))))double code(double re, double im) {
return log(sqrt((re * re) + (im * im)));
}
double code(double re, double im) {
double tmp;
if ((im * im) <= 4.496931482573535e-289) {
tmp = log(fabs(re));
} else if ((im * im) <= 2.8151563237733957e-47) {
tmp = log(sqrt((im * im) + (re * re)));
} else if ((im * im) <= 3.0416083611477998) {
tmp = log(fabs(re));
} else if ((im * im) <= 1.1242704904966132e+233) {
tmp = log(sqrt((im * im) + (re * re)));
} else {
tmp = log(fabs(im));
}
return tmp;
}










Bits error versus re










Bits error versus im
Results
| Alternative 1 | |
|---|---|
| Error | 14.1 |
| Cost | 14790 |
| Alternative 2 | |
|---|---|
| Error | 14.1 |
| Cost | 14790 |
| Alternative 3 | |
|---|---|
| Error | 25.2 |
| Cost | 8454 |
| Alternative 4 | |
|---|---|
| Error | 24.7 |
| Cost | 7106 |
| Alternative 5 | |
|---|---|
| Error | 35.2 |
| Cost | 6785 |
| Alternative 6 | |
|---|---|
| Error | 43.0 |
| Cost | 6785 |
| Alternative 7 | |
|---|---|
| Error | 57.0 |
| Cost | 64 |


if (*.f64 im im) < 4.49693148257353471e-289 or 2.81515632377339565e-47 < (*.f64 im im) < 3.0416083611477998Initial program 27.4
rmApplied add-sqr-sqrt_binary64_44127.4
Applied rem-sqrt-square_binary64_43227.4
Taylor expanded around inf 9.8
Simplified9.8
if 4.49693148257353471e-289 < (*.f64 im im) < 2.81515632377339565e-47 or 3.0416083611477998 < (*.f64 im im) < 1.1242704904966132e233Initial program 16.4
rmApplied +-commutative_binary64_34916.4
Simplified16.4
if 1.1242704904966132e233 < (*.f64 im im) Initial program 54.8
rmApplied add-sqr-sqrt_binary64_44154.8
Applied rem-sqrt-square_binary64_43254.8
Taylor expanded around 0 7.9
Simplified7.9
Final simplification11.8
herbie shell --seed 2021040
(FPCore (re im)
:name "math.log/1 on complex, real part"
:precision binary64
(log (sqrt (+ (* re re) (* im im)))))