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 <= -3.0495999745604484e+144) {
tmp = 0.5 * sqrt(2.0 * (re * -2.0));
} else if (re <= -2.4561711144511768e-77) {
tmp = 0.5 * sqrt(2.0 * (sqrt((re * re) + (im * im)) - re));
} else if (re <= 5.628209854884318e-65) {
tmp = 0.5 * sqrt(2.0 * (im - re));
} else if (re <= 1.3361830242464705e+154) {
tmp = 0.5 * (sqrt(2.0 * (im * im)) / sqrt(re + sqrt((re * re) + (im * im))));
} else {
tmp = 0.5 * sqrt(2.0 * ((im * im) / (re + re)));
}
return tmp;
}



Bits error versus re



Bits error versus im
Results
if re < -3.0495999745604484e144Initial program 61.5
Taylor expanded around -inf 9.4
Simplified9.4
if -3.0495999745604484e144 < re < -2.4561711144511768e-77Initial program 15.7
if -2.4561711144511768e-77 < re < 5.6282098548843183e-65Initial program 29.0
Taylor expanded around 0 11.1
if 5.6282098548843183e-65 < re < 1.3361830242464705e154Initial program 48.4
rmApplied flip--48.4
Simplified31.7
Simplified31.7
rmApplied associate-*r/31.7
Applied sqrt-div28.9
Simplified28.9
if 1.3361830242464705e154 < re Initial program 64.0
rmApplied flip--64.0
Simplified49.9
Simplified49.9
Taylor expanded around inf 29.9
Final simplification17.0
herbie shell --seed 2020338
(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)))))