\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.251241914834782347967678627443361391441 \cdot 10^{52}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.801608638015658355582080604789631060504 \cdot 10^{148}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r5874755 = a;
double r5874756 = c;
double r5874757 = r5874755 * r5874756;
double r5874758 = b;
double r5874759 = d;
double r5874760 = r5874758 * r5874759;
double r5874761 = r5874757 + r5874760;
double r5874762 = r5874756 * r5874756;
double r5874763 = r5874759 * r5874759;
double r5874764 = r5874762 + r5874763;
double r5874765 = r5874761 / r5874764;
return r5874765;
}
double f(double a, double b, double c, double d) {
double r5874766 = c;
double r5874767 = -2.2512419148347823e+52;
bool r5874768 = r5874766 <= r5874767;
double r5874769 = a;
double r5874770 = -r5874769;
double r5874771 = d;
double r5874772 = hypot(r5874771, r5874766);
double r5874773 = r5874770 / r5874772;
double r5874774 = 1.8016086380156584e+148;
bool r5874775 = r5874766 <= r5874774;
double r5874776 = b;
double r5874777 = r5874771 * r5874776;
double r5874778 = fma(r5874769, r5874766, r5874777);
double r5874779 = r5874778 / r5874772;
double r5874780 = r5874779 / r5874772;
double r5874781 = r5874769 / r5874772;
double r5874782 = r5874775 ? r5874780 : r5874781;
double r5874783 = r5874768 ? r5874773 : r5874782;
return r5874783;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.7 |
|---|---|
| Target | 0.4 |
| Herbie | 13.6 |
if c < -2.2512419148347823e+52Initial program 37.6
Simplified37.6
rmApplied add-sqr-sqrt37.6
Applied associate-/r*37.5
rmApplied fma-udef37.5
Applied hypot-def37.5
rmApplied fma-udef37.5
Applied hypot-def25.5
Taylor expanded around -inf 18.2
Simplified18.2
if -2.2512419148347823e+52 < c < 1.8016086380156584e+148Initial program 19.0
Simplified19.0
rmApplied add-sqr-sqrt19.0
Applied associate-/r*18.9
rmApplied fma-udef18.9
Applied hypot-def18.9
rmApplied fma-udef18.9
Applied hypot-def12.1
if 1.8016086380156584e+148 < c Initial program 45.0
Simplified45.0
rmApplied add-sqr-sqrt45.0
Applied associate-/r*45.0
rmApplied fma-udef45.0
Applied hypot-def45.0
rmApplied fma-udef45.0
Applied hypot-def28.7
Taylor expanded around inf 13.1
Final simplification13.6
herbie shell --seed 2019170 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
: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))))