\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 8.757218044757217587065948698275685768631 \cdot 10^{298}:\\
\;\;\;\;\frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r70792 = a;
double r70793 = c;
double r70794 = r70792 * r70793;
double r70795 = b;
double r70796 = d;
double r70797 = r70795 * r70796;
double r70798 = r70794 + r70797;
double r70799 = r70793 * r70793;
double r70800 = r70796 * r70796;
double r70801 = r70799 + r70800;
double r70802 = r70798 / r70801;
return r70802;
}
double f(double a, double b, double c, double d) {
double r70803 = a;
double r70804 = c;
double r70805 = r70803 * r70804;
double r70806 = b;
double r70807 = d;
double r70808 = r70806 * r70807;
double r70809 = r70805 + r70808;
double r70810 = r70804 * r70804;
double r70811 = r70807 * r70807;
double r70812 = r70810 + r70811;
double r70813 = r70809 / r70812;
double r70814 = 8.757218044757218e+298;
bool r70815 = r70813 <= r70814;
double r70816 = 1.0;
double r70817 = sqrt(r70812);
double r70818 = r70816 / r70817;
double r70819 = r70809 * r70818;
double r70820 = r70819 / r70817;
double r70821 = r70806 / r70817;
double r70822 = r70815 ? r70820 : r70821;
return r70822;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.5 |
| Herbie | 25.2 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 8.757218044757218e+298Initial program 14.0
rmApplied add-sqr-sqrt14.1
Applied associate-/r*14.0
rmApplied div-inv14.0
if 8.757218044757218e+298 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.6
rmApplied add-sqr-sqrt63.6
Applied associate-/r*63.6
Taylor expanded around 0 60.6
Final simplification25.2
herbie shell --seed 2019303
(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))))