\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.676220666344615615802840188676763171273 \cdot 10^{75}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 1.27854918231393790515454488962691098663 \cdot 10^{162}:\\
\;\;\;\;\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 r99592 = a;
double r99593 = c;
double r99594 = r99592 * r99593;
double r99595 = b;
double r99596 = d;
double r99597 = r99595 * r99596;
double r99598 = r99594 + r99597;
double r99599 = r99593 * r99593;
double r99600 = r99596 * r99596;
double r99601 = r99599 + r99600;
double r99602 = r99598 / r99601;
return r99602;
}
double f(double a, double b, double c, double d) {
double r99603 = c;
double r99604 = -1.6762206663446156e+75;
bool r99605 = r99603 <= r99604;
double r99606 = -1.0;
double r99607 = a;
double r99608 = r99606 * r99607;
double r99609 = d;
double r99610 = hypot(r99603, r99609);
double r99611 = 1.0;
double r99612 = r99610 * r99611;
double r99613 = r99608 / r99612;
double r99614 = 1.278549182313938e+162;
bool r99615 = r99603 <= r99614;
double r99616 = b;
double r99617 = r99616 * r99609;
double r99618 = fma(r99607, r99603, r99617);
double r99619 = r99618 / r99610;
double r99620 = r99619 / r99612;
double r99621 = r99607 / r99612;
double r99622 = r99615 ? r99620 : r99621;
double r99623 = r99605 ? r99613 : r99622;
return r99623;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.2 |
|---|---|
| Target | 0.4 |
| Herbie | 13.3 |
if c < -1.6762206663446156e+75Initial program 36.7
rmApplied add-sqr-sqrt36.7
Applied *-un-lft-identity36.7
Applied times-frac36.7
Simplified36.7
Simplified24.6
rmApplied associate-*r/24.6
Simplified24.5
Taylor expanded around -inf 17.0
if -1.6762206663446156e+75 < c < 1.278549182313938e+162Initial program 19.8
rmApplied add-sqr-sqrt19.8
Applied *-un-lft-identity19.8
Applied times-frac19.8
Simplified19.8
Simplified12.3
rmApplied associate-*r/12.2
Simplified12.1
if 1.278549182313938e+162 < c Initial program 45.5
rmApplied add-sqr-sqrt45.5
Applied *-un-lft-identity45.5
Applied times-frac45.5
Simplified45.5
Simplified31.0
rmApplied associate-*r/31.0
Simplified31.0
Taylor expanded around inf 13.9
Final simplification13.3
herbie shell --seed 2020001 +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))))