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 <= 6.700946626241751e-301) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(sqrt((im * im) + (re * re)) - re));
} else if (re <= 2.858449367873232e+66) {
tmp = 0.5 * sqrt(2.0 * (re + (cbrt(sqrt((im * im) + (re * re))) * (cbrt(sqrt((im * im) + (re * re))) * cbrt(sqrt((im * im) + (re * re)))))));
} else {
tmp = 0.5 * sqrt(2.0 * (re + re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 38.2 |
|---|---|
| Target | 33.3 |
| Herbie | 26.2 |
if re < 6.70094662624175065e-301Initial program 45.5
rmApplied flip-+45.4
Applied associate-*r/45.4
Applied sqrt-div45.5
Simplified34.8
if 6.70094662624175065e-301 < re < 2.85844936787323206e66Initial program 20.9
rmApplied add-cube-cbrt21.3
if 2.85844936787323206e66 < re Initial program 45.1
Taylor expanded around inf 11.9
Final simplification26.2
herbie shell --seed 2020322
(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)))))