\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.698029738904270629200661330806058795869 \cdot 10^{134}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 3.906672870888294447082944790587346450096 \cdot 10^{121}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\end{array}double f(double a, double b, double c, double d) {
double r117772 = a;
double r117773 = c;
double r117774 = r117772 * r117773;
double r117775 = b;
double r117776 = d;
double r117777 = r117775 * r117776;
double r117778 = r117774 + r117777;
double r117779 = r117773 * r117773;
double r117780 = r117776 * r117776;
double r117781 = r117779 + r117780;
double r117782 = r117778 / r117781;
return r117782;
}
double f(double a, double b, double c, double d) {
double r117783 = c;
double r117784 = -1.6980297389042706e+134;
bool r117785 = r117783 <= r117784;
double r117786 = -1.0;
double r117787 = a;
double r117788 = r117786 * r117787;
double r117789 = d;
double r117790 = hypot(r117783, r117789);
double r117791 = 1.0;
double r117792 = r117790 * r117791;
double r117793 = r117788 / r117792;
double r117794 = 3.9066728708882944e+121;
bool r117795 = r117783 <= r117794;
double r117796 = b;
double r117797 = r117796 * r117789;
double r117798 = fma(r117787, r117783, r117797);
double r117799 = r117798 / r117790;
double r117800 = r117799 / r117792;
double r117801 = r117787 / r117792;
double r117802 = r117795 ? r117800 : r117801;
double r117803 = r117785 ? r117793 : r117802;
return r117803;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 13.0 |
if c < -1.6980297389042706e+134Initial program 43.6
rmApplied add-sqr-sqrt43.6
Applied *-un-lft-identity43.6
Applied times-frac43.6
Simplified43.6
Simplified29.3
rmApplied associate-*r/29.3
Simplified29.3
Taylor expanded around -inf 14.9
if -1.6980297389042706e+134 < c < 3.9066728708882944e+121Initial program 19.0
rmApplied add-sqr-sqrt19.0
Applied *-un-lft-identity19.0
Applied times-frac19.0
Simplified19.0
Simplified12.4
rmApplied associate-*r/12.4
Simplified12.3
if 3.9066728708882944e+121 < c Initial program 41.3
rmApplied add-sqr-sqrt41.3
Applied *-un-lft-identity41.3
Applied times-frac41.3
Simplified41.3
Simplified28.4
rmApplied associate-*r/28.4
Simplified28.4
Taylor expanded around inf 14.3
Final simplification13.0
herbie shell --seed 2020002 +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))))