\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 4.737122355537421671534518653596175011386 \cdot 10^{285}:\\
\;\;\;\;\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 r85097 = a;
double r85098 = c;
double r85099 = r85097 * r85098;
double r85100 = b;
double r85101 = d;
double r85102 = r85100 * r85101;
double r85103 = r85099 + r85102;
double r85104 = r85098 * r85098;
double r85105 = r85101 * r85101;
double r85106 = r85104 + r85105;
double r85107 = r85103 / r85106;
return r85107;
}
double f(double a, double b, double c, double d) {
double r85108 = a;
double r85109 = c;
double r85110 = r85108 * r85109;
double r85111 = b;
double r85112 = d;
double r85113 = r85111 * r85112;
double r85114 = r85110 + r85113;
double r85115 = r85109 * r85109;
double r85116 = r85112 * r85112;
double r85117 = r85115 + r85116;
double r85118 = r85114 / r85117;
double r85119 = 4.7371223555374217e+285;
bool r85120 = r85118 <= r85119;
double r85121 = sqrt(r85117);
double r85122 = r85114 / r85121;
double r85123 = r85122 / r85121;
double r85124 = -r85108;
double r85125 = r85124 / r85121;
double r85126 = r85120 ? r85123 : r85125;
return r85126;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.3 |
| Herbie | 25.1 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 4.7371223555374217e+285Initial program 13.7
rmApplied add-sqr-sqrt13.7
Applied associate-/r*13.6
if 4.7371223555374217e+285 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.6
rmApplied add-sqr-sqrt62.7
Applied associate-/r*62.6
Taylor expanded around -inf 60.2
Simplified60.2
Final simplification25.1
herbie shell --seed 2019323
(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))))