0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} + re\right)}
\begin{array}{l}
\mathbf{if}\;re \leq -2.926404548759696 \cdot 10^{+196}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\frac{im \cdot im}{re} \cdot \mathsf{fma}\left(0.125, \frac{im}{\frac{re \cdot re}{im}}, -0.5\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(re + \mathsf{hypot}\left(re, im\right)\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.926404548759696e+196)
(*
0.5
(sqrt
(* 2.0 (* (/ (* im im) re) (fma 0.125 (/ im (/ (* re re) im)) -0.5)))))
(* 0.5 (sqrt (* 2.0 (+ re (hypot re im)))))))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.926404548759696e+196) {
tmp = 0.5 * sqrt(2.0 * (((im * im) / re) * fma(0.125, (im / ((re * re) / im)), -0.5)));
} else {
tmp = 0.5 * sqrt(2.0 * (re + hypot(re, im)));
}
return tmp;
}




Bits error versus re




Bits error versus im
| Original | 38.7 |
|---|---|
| Target | 33.9 |
| Herbie | 11.7 |
if re < -2.92640454875969598e196Initial program 64.0
Simplified45.2
Applied add-cube-cbrt_binary6454.9
Applied fma-def_binary6457.4
Applied add-exp-log_binary6457.8
Taylor expanded in re around -inf 40.7
Simplified31.1
if -2.92640454875969598e196 < re Initial program 36.3
Simplified9.9
Final simplification11.7
herbie shell --seed 2022103
(FPCore (re im)
:name "math.sqrt on complex, real part"
:precision binary64
:herbie-target
(if (< re 0.0) (* 0.5 (* (sqrt 2.0) (sqrt (/ (* im im) (- (sqrt (+ (* re re) (* im im))) re))))) (* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))
(* 0.5 (sqrt (* 2.0 (+ (sqrt (+ (* re re) (* im im))) re)))))