\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -1.300179201415138562389146100214075083549 \cdot 10^{53}:\\
\;\;\;\;-\frac{b}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{d \cdot d + c \cdot c}{a \cdot c + b \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r83272 = a;
double r83273 = c;
double r83274 = r83272 * r83273;
double r83275 = b;
double r83276 = d;
double r83277 = r83275 * r83276;
double r83278 = r83274 + r83277;
double r83279 = r83273 * r83273;
double r83280 = r83276 * r83276;
double r83281 = r83279 + r83280;
double r83282 = r83278 / r83281;
return r83282;
}
double f(double a, double b, double c, double d) {
double r83283 = d;
double r83284 = -1.3001792014151386e+53;
bool r83285 = r83283 <= r83284;
double r83286 = b;
double r83287 = r83283 * r83283;
double r83288 = c;
double r83289 = r83288 * r83288;
double r83290 = r83287 + r83289;
double r83291 = sqrt(r83290);
double r83292 = r83286 / r83291;
double r83293 = -r83292;
double r83294 = 1.0;
double r83295 = a;
double r83296 = r83295 * r83288;
double r83297 = r83286 * r83283;
double r83298 = r83296 + r83297;
double r83299 = r83290 / r83298;
double r83300 = r83294 / r83299;
double r83301 = r83285 ? r83293 : r83300;
return r83301;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.4 |
| Herbie | 26.2 |
if d < -1.3001792014151386e+53Initial program 35.6
rmApplied add-sqr-sqrt35.6
Applied associate-/r*35.6
Simplified35.6
Taylor expanded around -inf 36.7
Simplified36.7
if -1.3001792014151386e+53 < d Initial program 23.1
rmApplied add-sqr-sqrt23.1
Applied associate-/r*23.1
Simplified23.1
rmApplied *-un-lft-identity23.1
Applied sqrt-prod23.1
Applied *-un-lft-identity23.1
Applied times-frac23.1
Applied associate-/l*23.3
Simplified23.3
Final simplification26.2
herbie shell --seed 2019194
(FPCore (a b c d)
:name "Complex division, real part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))