\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 1.184813700156011083109181895909360357652 \cdot 10^{305}:\\
\;\;\;\;\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 r110201 = a;
double r110202 = c;
double r110203 = r110201 * r110202;
double r110204 = b;
double r110205 = d;
double r110206 = r110204 * r110205;
double r110207 = r110203 + r110206;
double r110208 = r110202 * r110202;
double r110209 = r110205 * r110205;
double r110210 = r110208 + r110209;
double r110211 = r110207 / r110210;
return r110211;
}
double f(double a, double b, double c, double d) {
double r110212 = a;
double r110213 = c;
double r110214 = r110212 * r110213;
double r110215 = b;
double r110216 = d;
double r110217 = r110215 * r110216;
double r110218 = r110214 + r110217;
double r110219 = r110213 * r110213;
double r110220 = r110216 * r110216;
double r110221 = r110219 + r110220;
double r110222 = r110218 / r110221;
double r110223 = 1.184813700156011e+305;
bool r110224 = r110222 <= r110223;
double r110225 = sqrt(r110221);
double r110226 = r110218 / r110225;
double r110227 = r110226 / r110225;
double r110228 = r110212 / r110225;
double r110229 = r110224 ? r110227 : r110228;
return r110229;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 25.1 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 1.184813700156011e+305Initial program 14.1
rmApplied add-sqr-sqrt14.1
Applied associate-/r*14.0
if 1.184813700156011e+305 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.9
rmApplied add-sqr-sqrt63.9
Applied associate-/r*63.9
Taylor expanded around inf 60.5
Final simplification25.1
herbie shell --seed 2019362
(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))))