\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.157198741477479343907715443178213541736 \cdot 10^{265}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r76663 = a;
double r76664 = c;
double r76665 = r76663 * r76664;
double r76666 = b;
double r76667 = d;
double r76668 = r76666 * r76667;
double r76669 = r76665 + r76668;
double r76670 = r76664 * r76664;
double r76671 = r76667 * r76667;
double r76672 = r76670 + r76671;
double r76673 = r76669 / r76672;
return r76673;
}
double f(double a, double b, double c, double d) {
double r76674 = a;
double r76675 = c;
double r76676 = r76674 * r76675;
double r76677 = b;
double r76678 = d;
double r76679 = r76677 * r76678;
double r76680 = r76676 + r76679;
double r76681 = r76675 * r76675;
double r76682 = r76678 * r76678;
double r76683 = r76681 + r76682;
double r76684 = r76680 / r76683;
double r76685 = 3.1571987414774793e+265;
bool r76686 = r76684 <= r76685;
double r76687 = fma(r76674, r76675, r76679);
double r76688 = hypot(r76675, r76678);
double r76689 = r76687 / r76688;
double r76690 = r76689 / r76688;
double r76691 = r76677 / r76688;
double r76692 = r76686 ? r76690 : r76691;
return r76692;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.3 |
| Herbie | 14.2 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.1571987414774793e+265Initial program 13.8
rmApplied add-sqr-sqrt13.8
Applied *-un-lft-identity13.8
Applied times-frac13.8
Simplified13.8
Simplified2.7
rmApplied associate-*r/2.6
Simplified2.5
if 3.1571987414774793e+265 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 61.8
rmApplied add-sqr-sqrt61.8
Applied *-un-lft-identity61.8
Applied times-frac61.8
Simplified61.8
Simplified58.9
rmApplied associate-*r/58.9
Simplified58.9
Taylor expanded around 0 49.1
Final simplification14.2
herbie shell --seed 2019323 +o rules:numerics
(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))))