0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -1.0699785804869837 \cdot 10^{+71}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq -8.505474022050854 \cdot 10^{-135}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\
\mathbf{elif}\;re \leq 5.24919610962508 \cdot 10^{+23}:\\
\;\;\;\;0.5 \cdot {\left(2 \cdot im\right)}^{0.5}\\
\mathbf{elif}\;re \leq 2.2785101745041676 \cdot 10^{+152}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \frac{im \cdot im}{re + \sqrt{re \cdot re + im \cdot im}}}\\
\mathbf{elif}\;re \leq 2.4827971193717914 \cdot 10^{+172}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\left(im + 0.5 \cdot \frac{re}{\frac{im}{re}}\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(0.5 \cdot \frac{im \cdot im}{re}\right)}\\
\end{array}(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(FPCore (re im)
:precision binary64
(if (<= re -1.0699785804869837e+71)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re -8.505474022050854e-135)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))))
(if (<= re 5.24919610962508e+23)
(* 0.5 (pow (* 2.0 im) 0.5))
(if (<= re 2.2785101745041676e+152)
(*
0.5
(sqrt (* 2.0 (/ (* im im) (+ re (sqrt (+ (* re re) (* im im))))))))
(if (<= re 2.4827971193717914e+172)
(* 0.5 (sqrt (* 2.0 (- (+ im (* 0.5 (/ re (/ im re)))) re))))
(* 0.5 (sqrt (* 2.0 (* 0.5 (/ (* im im) re)))))))))))double code(double re, double im) {
return 0.5 * sqrt(2.0 * (sqrt((re * re) + (im * im)) - re));
}
double code(double re, double im) {
double tmp;
if (re <= -1.0699785804869837e+71) {
tmp = 0.5 * sqrt(2.0 * (re * -2.0));
} else if (re <= -8.505474022050854e-135) {
tmp = 0.5 * sqrt(2.0 * (sqrt((re * re) + (im * im)) - re));
} else if (re <= 5.24919610962508e+23) {
tmp = 0.5 * pow((2.0 * im), 0.5);
} else if (re <= 2.2785101745041676e+152) {
tmp = 0.5 * sqrt(2.0 * ((im * im) / (re + sqrt((re * re) + (im * im)))));
} else if (re <= 2.4827971193717914e+172) {
tmp = 0.5 * sqrt(2.0 * ((im + (0.5 * (re / (im / re)))) - re));
} else {
tmp = 0.5 * sqrt(2.0 * (0.5 * ((im * im) / re)));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if re < -1.0699785804869837e71Initial program 48.1
Taylor expanded around -inf 12.3
Simplified12.3
if -1.0699785804869837e71 < re < -8.5054740220508541e-135Initial program 15.8
rmApplied *-un-lft-identity_binary6415.8
Applied cancel-sign-sub-inv_binary6415.8
if -8.5054740220508541e-135 < re < 5.24919610962508002e23Initial program 32.9
Taylor expanded around 0 13.7
Simplified13.7
Taylor expanded around 0 14.1
Simplified14.1
rmApplied pow1/2_binary6414.1
Applied pow1/2_binary6414.1
Applied pow-prod-down_binary6413.8
Simplified13.8
if 5.24919610962508002e23 < re < 2.27851017450416761e152Initial program 51.3
rmApplied flip--_binary6451.3
Simplified30.8
Simplified30.8
if 2.27851017450416761e152 < re < 2.4827971193717914e172Initial program 62.5
Taylor expanded around 0 60.8
Simplified60.8
rmApplied associate-/l*_binary6445.6
if 2.4827971193717914e172 < re Initial program 64.0
Taylor expanded around inf 31.3
Simplified31.3
Final simplification17.9
herbie shell --seed 2021126
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
:pre (> im 0.0)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))