\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.1536238602847571 \cdot 10^{76}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 1.7187819587037017 \cdot 10^{178}:\\
\;\;\;\;\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 r108455 = a;
double r108456 = c;
double r108457 = r108455 * r108456;
double r108458 = b;
double r108459 = d;
double r108460 = r108458 * r108459;
double r108461 = r108457 + r108460;
double r108462 = r108456 * r108456;
double r108463 = r108459 * r108459;
double r108464 = r108462 + r108463;
double r108465 = r108461 / r108464;
return r108465;
}
double f(double a, double b, double c, double d) {
double r108466 = c;
double r108467 = -4.153623860284757e+76;
bool r108468 = r108466 <= r108467;
double r108469 = -1.0;
double r108470 = a;
double r108471 = r108469 * r108470;
double r108472 = d;
double r108473 = hypot(r108466, r108472);
double r108474 = 1.0;
double r108475 = r108473 * r108474;
double r108476 = r108471 / r108475;
double r108477 = 1.7187819587037017e+178;
bool r108478 = r108466 <= r108477;
double r108479 = b;
double r108480 = r108479 * r108472;
double r108481 = fma(r108470, r108466, r108480);
double r108482 = r108481 / r108473;
double r108483 = r108482 / r108475;
double r108484 = r108470 / r108475;
double r108485 = r108478 ? r108483 : r108484;
double r108486 = r108468 ? r108476 : r108485;
return r108486;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.3 |
| Herbie | 13.8 |
if c < -4.153623860284757e+76Initial program 38.7
rmApplied add-sqr-sqrt38.7
Applied *-un-lft-identity38.7
Applied times-frac38.7
Simplified38.7
Simplified26.7
rmApplied associate-*r/26.7
Simplified26.6
Taylor expanded around -inf 18.0
if -4.153623860284757e+76 < c < 1.7187819587037017e+178Initial program 20.0
rmApplied add-sqr-sqrt20.0
Applied *-un-lft-identity20.0
Applied times-frac20.0
Simplified20.0
Simplified12.6
rmApplied associate-*r/12.6
Simplified12.5
if 1.7187819587037017e+178 < c Initial program 45.1
rmApplied add-sqr-sqrt45.1
Applied *-un-lft-identity45.1
Applied times-frac45.1
Simplified45.1
Simplified31.0
rmApplied associate-*r/31.0
Simplified30.9
Taylor expanded around inf 14.4
Final simplification13.8
herbie shell --seed 2020027 +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))))