\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 r97828 = a;
double r97829 = c;
double r97830 = r97828 * r97829;
double r97831 = b;
double r97832 = d;
double r97833 = r97831 * r97832;
double r97834 = r97830 + r97833;
double r97835 = r97829 * r97829;
double r97836 = r97832 * r97832;
double r97837 = r97835 + r97836;
double r97838 = r97834 / r97837;
return r97838;
}
double f(double a, double b, double c, double d) {
double r97839 = a;
double r97840 = c;
double r97841 = r97839 * r97840;
double r97842 = b;
double r97843 = d;
double r97844 = r97842 * r97843;
double r97845 = r97841 + r97844;
double r97846 = r97840 * r97840;
double r97847 = r97843 * r97843;
double r97848 = r97846 + r97847;
double r97849 = r97845 / r97848;
double r97850 = 3.1571987414774793e+265;
bool r97851 = r97849 <= r97850;
double r97852 = fma(r97839, r97840, r97844);
double r97853 = hypot(r97840, r97843);
double r97854 = r97852 / r97853;
double r97855 = r97854 / r97853;
double r97856 = r97842 / r97853;
double r97857 = r97851 ? r97855 : r97856;
return r97857;
}




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))))