\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.2063458127550573 \cdot 10^{+100}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 4.054287420560557 \cdot 10^{+138}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, c, \left(d \cdot b\right)\right)}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r1747463 = a;
double r1747464 = c;
double r1747465 = r1747463 * r1747464;
double r1747466 = b;
double r1747467 = d;
double r1747468 = r1747466 * r1747467;
double r1747469 = r1747465 + r1747468;
double r1747470 = r1747464 * r1747464;
double r1747471 = r1747467 * r1747467;
double r1747472 = r1747470 + r1747471;
double r1747473 = r1747469 / r1747472;
return r1747473;
}
double f(double a, double b, double c, double d) {
double r1747474 = c;
double r1747475 = -2.2063458127550573e+100;
bool r1747476 = r1747474 <= r1747475;
double r1747477 = a;
double r1747478 = -r1747477;
double r1747479 = d;
double r1747480 = hypot(r1747474, r1747479);
double r1747481 = r1747478 / r1747480;
double r1747482 = 4.054287420560557e+138;
bool r1747483 = r1747474 <= r1747482;
double r1747484 = 1.0;
double r1747485 = b;
double r1747486 = r1747479 * r1747485;
double r1747487 = fma(r1747477, r1747474, r1747486);
double r1747488 = r1747480 / r1747487;
double r1747489 = r1747484 / r1747488;
double r1747490 = r1747489 / r1747480;
double r1747491 = r1747477 / r1747480;
double r1747492 = r1747483 ? r1747490 : r1747491;
double r1747493 = r1747476 ? r1747481 : r1747492;
return r1747493;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.1 |
|---|---|
| Target | 0.5 |
| Herbie | 13.1 |
if c < -2.2063458127550573e+100Initial program 38.4
rmApplied add-sqr-sqrt38.4
Applied associate-/r*38.4
rmApplied hypot-def38.4
rmApplied clear-num38.4
Simplified25.2
Taylor expanded around -inf 16.7
Simplified16.7
if -2.2063458127550573e+100 < c < 4.054287420560557e+138Initial program 18.6
rmApplied add-sqr-sqrt18.6
Applied associate-/r*18.5
rmApplied hypot-def18.5
rmApplied clear-num18.6
Simplified11.8
if 4.054287420560557e+138 < c Initial program 45.0
rmApplied add-sqr-sqrt45.0
Applied associate-/r*45.0
rmApplied hypot-def45.0
rmApplied clear-num45.0
Simplified29.1
Taylor expanded around inf 14.5
Final simplification13.1
herbie shell --seed 2019128 +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))))