\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.741292395726274 \cdot 10^{176}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 6.2260315404588448 \cdot 10^{142}:\\
\;\;\;\;\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 r120517 = a;
double r120518 = c;
double r120519 = r120517 * r120518;
double r120520 = b;
double r120521 = d;
double r120522 = r120520 * r120521;
double r120523 = r120519 + r120522;
double r120524 = r120518 * r120518;
double r120525 = r120521 * r120521;
double r120526 = r120524 + r120525;
double r120527 = r120523 / r120526;
return r120527;
}
double f(double a, double b, double c, double d) {
double r120528 = c;
double r120529 = -2.741292395726274e+176;
bool r120530 = r120528 <= r120529;
double r120531 = -1.0;
double r120532 = a;
double r120533 = r120531 * r120532;
double r120534 = d;
double r120535 = hypot(r120528, r120534);
double r120536 = 1.0;
double r120537 = r120535 * r120536;
double r120538 = r120533 / r120537;
double r120539 = 6.226031540458845e+142;
bool r120540 = r120528 <= r120539;
double r120541 = b;
double r120542 = r120541 * r120534;
double r120543 = fma(r120532, r120528, r120542);
double r120544 = r120543 / r120535;
double r120545 = r120544 / r120537;
double r120546 = r120532 / r120537;
double r120547 = r120540 ? r120545 : r120546;
double r120548 = r120530 ? r120538 : r120547;
return r120548;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 13.3 |
if c < -2.741292395726274e+176Initial program 42.3
rmApplied add-sqr-sqrt42.3
Applied *-un-lft-identity42.3
Applied times-frac42.3
Simplified42.3
Simplified28.2
rmApplied associate-*r/28.2
Simplified28.1
Taylor expanded around -inf 12.1
if -2.741292395726274e+176 < c < 6.226031540458845e+142Initial program 20.2
rmApplied add-sqr-sqrt20.2
Applied *-un-lft-identity20.2
Applied times-frac20.2
Simplified20.2
Simplified13.5
rmApplied associate-*r/13.5
Simplified13.4
if 6.226031540458845e+142 < c Initial program 42.3
rmApplied add-sqr-sqrt42.3
Applied *-un-lft-identity42.3
Applied times-frac42.3
Simplified42.3
Simplified27.4
rmApplied associate-*r/27.4
Simplified27.3
Taylor expanded around inf 13.4
Final simplification13.3
herbie shell --seed 2020089 +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))))