\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 3.205157260915315763715079288223481241169 \cdot 10^{295}:\\
\;\;\;\;\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{b}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r97217 = a;
double r97218 = c;
double r97219 = r97217 * r97218;
double r97220 = b;
double r97221 = d;
double r97222 = r97220 * r97221;
double r97223 = r97219 + r97222;
double r97224 = r97218 * r97218;
double r97225 = r97221 * r97221;
double r97226 = r97224 + r97225;
double r97227 = r97223 / r97226;
return r97227;
}
double f(double a, double b, double c, double d) {
double r97228 = a;
double r97229 = c;
double r97230 = r97228 * r97229;
double r97231 = b;
double r97232 = d;
double r97233 = r97231 * r97232;
double r97234 = r97230 + r97233;
double r97235 = r97229 * r97229;
double r97236 = r97232 * r97232;
double r97237 = r97235 + r97236;
double r97238 = r97234 / r97237;
double r97239 = 3.2051572609153158e+295;
bool r97240 = r97238 <= r97239;
double r97241 = sqrt(r97237);
double r97242 = r97234 / r97241;
double r97243 = r97242 / r97241;
double r97244 = r97231 / r97241;
double r97245 = r97240 ? r97243 : r97244;
return r97245;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 25.1 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.2051572609153158e+295Initial program 13.9
rmApplied add-sqr-sqrt13.9
Applied associate-/r*13.8
if 3.2051572609153158e+295 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.2
rmApplied add-sqr-sqrt63.2
Applied associate-/r*63.2
Taylor expanded around 0 60.2
Final simplification25.1
herbie shell --seed 2019212
(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))))