\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -1.1964723101605788 \cdot 10^{+201}:\\
\;\;\;\;\frac{-1}{\mathsf{hypot}\left(d, c\right)} \cdot b\\
\mathbf{elif}\;d \le 3.85213929759163 \cdot 10^{+150}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, d, c \cdot a\right)}{\mathsf{hypot}\left(d, c\right)} \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;b \cdot \frac{1}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r2523509 = a;
double r2523510 = c;
double r2523511 = r2523509 * r2523510;
double r2523512 = b;
double r2523513 = d;
double r2523514 = r2523512 * r2523513;
double r2523515 = r2523511 + r2523514;
double r2523516 = r2523510 * r2523510;
double r2523517 = r2523513 * r2523513;
double r2523518 = r2523516 + r2523517;
double r2523519 = r2523515 / r2523518;
return r2523519;
}
double f(double a, double b, double c, double d) {
double r2523520 = d;
double r2523521 = -1.1964723101605788e+201;
bool r2523522 = r2523520 <= r2523521;
double r2523523 = -1.0;
double r2523524 = c;
double r2523525 = hypot(r2523520, r2523524);
double r2523526 = r2523523 / r2523525;
double r2523527 = b;
double r2523528 = r2523526 * r2523527;
double r2523529 = 3.85213929759163e+150;
bool r2523530 = r2523520 <= r2523529;
double r2523531 = a;
double r2523532 = r2523524 * r2523531;
double r2523533 = fma(r2523527, r2523520, r2523532);
double r2523534 = r2523533 / r2523525;
double r2523535 = 1.0;
double r2523536 = r2523535 / r2523525;
double r2523537 = r2523534 * r2523536;
double r2523538 = r2523527 * r2523536;
double r2523539 = r2523530 ? r2523537 : r2523538;
double r2523540 = r2523522 ? r2523528 : r2523539;
return r2523540;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.2 |
|---|---|
| Target | 0.4 |
| Herbie | 12.7 |
if d < -1.1964723101605788e+201Initial program 43.3
Simplified43.3
rmApplied add-sqr-sqrt43.3
Applied associate-/r*43.3
rmApplied clear-num43.3
Simplified32.0
rmApplied associate-/r/31.3
Taylor expanded around -inf 10.3
Simplified10.3
if -1.1964723101605788e+201 < d < 3.85213929759163e+150Initial program 20.5
Simplified20.5
rmApplied add-sqr-sqrt20.5
Applied associate-/r*20.4
rmApplied clear-num20.7
Simplified13.1
rmApplied associate-/r/12.8
if 3.85213929759163e+150 < d Initial program 45.3
Simplified45.3
rmApplied add-sqr-sqrt45.3
Applied associate-/r*45.3
rmApplied clear-num45.3
Simplified29.6
rmApplied associate-/r/29.1
Taylor expanded around inf 14.0
Final simplification12.7
herbie shell --seed 2019146 +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))))