\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.1105748288996943 \cdot 10^{+133}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 7.527112129916618 \cdot 10^{+115}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, \left(d \cdot b\right)\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 r23299673 = a;
double r23299674 = c;
double r23299675 = r23299673 * r23299674;
double r23299676 = b;
double r23299677 = d;
double r23299678 = r23299676 * r23299677;
double r23299679 = r23299675 + r23299678;
double r23299680 = r23299674 * r23299674;
double r23299681 = r23299677 * r23299677;
double r23299682 = r23299680 + r23299681;
double r23299683 = r23299679 / r23299682;
return r23299683;
}
double f(double a, double b, double c, double d) {
double r23299684 = c;
double r23299685 = -1.1105748288996943e+133;
bool r23299686 = r23299684 <= r23299685;
double r23299687 = a;
double r23299688 = -r23299687;
double r23299689 = d;
double r23299690 = hypot(r23299689, r23299684);
double r23299691 = r23299688 / r23299690;
double r23299692 = 7.527112129916618e+115;
bool r23299693 = r23299684 <= r23299692;
double r23299694 = b;
double r23299695 = r23299689 * r23299694;
double r23299696 = fma(r23299687, r23299684, r23299695);
double r23299697 = r23299696 / r23299690;
double r23299698 = r23299697 / r23299690;
double r23299699 = r23299687 / r23299690;
double r23299700 = r23299693 ? r23299698 : r23299699;
double r23299701 = r23299686 ? r23299691 : r23299700;
return r23299701;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.2 |
|---|---|
| Target | 0.5 |
| Herbie | 13.1 |
if c < -1.1105748288996943e+133Initial program 42.1
Simplified42.1
rmApplied add-sqr-sqrt42.1
Applied associate-/r*42.1
rmApplied fma-udef42.1
Applied hypot-def42.1
rmApplied fma-udef42.1
Applied hypot-def27.1
Taylor expanded around -inf 15.3
Simplified15.3
if -1.1105748288996943e+133 < c < 7.527112129916618e+115Initial program 19.1
Simplified19.1
rmApplied add-sqr-sqrt19.1
Applied associate-/r*19.0
rmApplied fma-udef19.0
Applied hypot-def19.0
rmApplied fma-udef19.0
Applied hypot-def11.8
if 7.527112129916618e+115 < c Initial program 41.1
Simplified41.1
rmApplied add-sqr-sqrt41.1
Applied associate-/r*41.1
rmApplied fma-udef41.1
Applied hypot-def41.1
rmApplied fma-udef41.1
Applied hypot-def27.5
Taylor expanded around inf 16.5
Final simplification13.1
herbie shell --seed 2019121 +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))))