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.0515333860087074e+143) {
tmp = 0.5 * (sqrt((im * im) * 2.0) / sqrt(re * -2.0));
} else if (re <= 8.161050826261294e-169) {
tmp = 0.5 * ((fabs(im) / sqrt(sqrt(sqrt((im * im) + (re * re)) - re))) * (sqrt(2.0) / sqrt(sqrt(sqrt((im * im) + (re * re)) - re))));
} else {
tmp = 0.5 * sqrt(2.0 * (re + re));
}
return tmp;
}




Bits error versus re




Bits error versus im
Results
| Original | 37.9 |
|---|---|
| Target | 33.1 |
| Herbie | 22.8 |
if re < -1.05153338600870742e143Initial program 63.2
rmApplied flip-+63.2
Applied associate-*r/63.2
Applied sqrt-div63.2
Simplified49.1
Taylor expanded around -inf 19.4
Simplified19.4
if -1.05153338600870742e143 < re < 8.1610508262612942e-169Initial program 36.9
rmApplied flip-+37.2
Applied associate-*r/37.2
Applied sqrt-div37.5
Simplified30.4
rmApplied add-sqr-sqrt30.4
Applied sqrt-prod30.6
Applied sqrt-prod30.5
Applied times-frac30.5
Simplified23.1
Simplified23.1
if 8.1610508262612942e-169 < re Initial program 31.1
Taylor expanded around inf 23.4
Final simplification22.8
herbie shell --seed 2020338
(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)))))