\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 5.576513857527639342984990951575169691567 \cdot 10^{267}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r94475 = a;
double r94476 = c;
double r94477 = r94475 * r94476;
double r94478 = b;
double r94479 = d;
double r94480 = r94478 * r94479;
double r94481 = r94477 + r94480;
double r94482 = r94476 * r94476;
double r94483 = r94479 * r94479;
double r94484 = r94482 + r94483;
double r94485 = r94481 / r94484;
return r94485;
}
double f(double a, double b, double c, double d) {
double r94486 = a;
double r94487 = c;
double r94488 = r94486 * r94487;
double r94489 = b;
double r94490 = d;
double r94491 = r94489 * r94490;
double r94492 = r94488 + r94491;
double r94493 = r94487 * r94487;
double r94494 = r94490 * r94490;
double r94495 = r94493 + r94494;
double r94496 = r94492 / r94495;
double r94497 = 5.576513857527639e+267;
bool r94498 = r94496 <= r94497;
double r94499 = sqrt(r94495);
double r94500 = r94492 / r94499;
double r94501 = r94500 / r94499;
double r94502 = -r94486;
double r94503 = r94502 / r94499;
double r94504 = r94498 ? r94501 : r94503;
return r94504;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 25.8 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 5.576513857527639e+267Initial program 14.2
rmApplied add-sqr-sqrt14.2
Applied associate-/r*14.1
if 5.576513857527639e+267 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.0
rmApplied add-sqr-sqrt62.0
Applied associate-/r*62.0
Taylor expanded around -inf 60.4
Simplified60.4
Final simplification25.8
herbie shell --seed 2019235
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
: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))))