0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\begin{array}{l}
\mathbf{if}\;re \leq -2.1320242768716358 \cdot 10^{+145}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re \cdot -2\right)}\\
\mathbf{elif}\;re \leq -1.4186350356885884 \cdot 10^{-103}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\
\mathbf{elif}\;re \leq -5.178839982241449 \cdot 10^{-111}:\\
\;\;\;\;0.5 \cdot {\left(2 \cdot im\right)}^{0.5}\\
\mathbf{elif}\;re \leq -1.2571986496294196 \cdot 10^{-136}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{im \cdot im + re \cdot re} - re\right)}\\
\mathbf{elif}\;re \leq 24805927178.950237:\\
\;\;\;\;0.5 \cdot {\left(2 \cdot im\right)}^{0.5}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(\left(\sqrt{0.5} \cdot \left(im \cdot \sqrt{2}\right)\right) \cdot \sqrt{\frac{1}{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 -2.1320242768716358e+145)
(* 0.5 (sqrt (* 2.0 (* re -2.0))))
(if (<= re -1.4186350356885884e-103)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* im im) (* re re))) re))))
(if (<= re -5.178839982241449e-111)
(* 0.5 (pow (* 2.0 im) 0.5))
(if (<= re -1.2571986496294196e-136)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* im im) (* re re))) re))))
(if (<= re 24805927178.950237)
(* 0.5 (pow (* 2.0 im) 0.5))
(* 0.5 (* (* (sqrt 0.5) (* im (sqrt 2.0))) (sqrt (/ 1.0 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 <= -2.1320242768716358e+145) {
tmp = 0.5 * sqrt(2.0 * (re * -2.0));
} else if (re <= -1.4186350356885884e-103) {
tmp = 0.5 * sqrt(2.0 * (sqrt((im * im) + (re * re)) - re));
} else if (re <= -5.178839982241449e-111) {
tmp = 0.5 * pow((2.0 * im), 0.5);
} else if (re <= -1.2571986496294196e-136) {
tmp = 0.5 * sqrt(2.0 * (sqrt((im * im) + (re * re)) - re));
} else if (re <= 24805927178.950237) {
tmp = 0.5 * pow((2.0 * im), 0.5);
} else {
tmp = 0.5 * ((sqrt(0.5) * (im * sqrt(2.0))) * sqrt(1.0 / re));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if re < -2.1320242768716358e145Initial program 61.9
Taylor expanded around -inf 8.1
Simplified8.1
if -2.1320242768716358e145 < re < -1.418635035688588e-103 or -5.178839982241449e-111 < re < -1.25719864962941956e-136Initial program 15.4
rmApplied +-commutative_binary6415.4
if -1.418635035688588e-103 < re < -5.178839982241449e-111 or -1.25719864962941956e-136 < re < 24805927178.9502373Initial program 31.8
Taylor expanded around 0 12.9
Simplified12.9
Taylor expanded around 0 13.4
Simplified13.4
rmApplied add-sqr-sqrt_binary6413.5
Applied associate-*l*_binary6413.4
Simplified13.4
rmApplied pow1_binary6413.4
Applied sqrt-pow1_binary6413.4
Applied pow1_binary6413.4
Applied sqrt-pow1_binary6413.4
Applied pow-prod-down_binary6413.3
Applied pow1_binary6413.3
Applied sqrt-pow1_binary6413.3
Applied pow-prod-down_binary6413.5
Simplified13.1
if 24805927178.9502373 < re Initial program 57.3
Taylor expanded around 0 15.2
Final simplification13.5
herbie shell --seed 2021118
(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)))))