\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.09704610901182658 \cdot 10^{117}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 5.2660357604755783 \cdot 10^{182}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\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 r90396 = a;
double r90397 = c;
double r90398 = r90396 * r90397;
double r90399 = b;
double r90400 = d;
double r90401 = r90399 * r90400;
double r90402 = r90398 + r90401;
double r90403 = r90397 * r90397;
double r90404 = r90400 * r90400;
double r90405 = r90403 + r90404;
double r90406 = r90402 / r90405;
return r90406;
}
double f(double a, double b, double c, double d) {
double r90407 = c;
double r90408 = -1.0970461090118266e+117;
bool r90409 = r90407 <= r90408;
double r90410 = -1.0;
double r90411 = a;
double r90412 = r90410 * r90411;
double r90413 = d;
double r90414 = hypot(r90407, r90413);
double r90415 = 1.0;
double r90416 = r90414 * r90415;
double r90417 = r90412 / r90416;
double r90418 = 5.2660357604755783e+182;
bool r90419 = r90407 <= r90418;
double r90420 = b;
double r90421 = r90420 * r90413;
double r90422 = fma(r90411, r90407, r90421);
double r90423 = r90415 / r90414;
double r90424 = r90422 * r90423;
double r90425 = r90424 / r90416;
double r90426 = r90411 / r90416;
double r90427 = r90419 ? r90425 : r90426;
double r90428 = r90409 ? r90417 : r90427;
return r90428;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.5 |
|---|---|
| Target | 0.5 |
| Herbie | 12.7 |
if c < -1.0970461090118266e+117Initial program 40.9
rmApplied add-sqr-sqrt40.9
Applied *-un-lft-identity40.9
Applied times-frac40.9
Simplified40.9
Simplified27.4
rmApplied associate-*r/27.4
Simplified27.4
Taylor expanded around -inf 15.6
if -1.0970461090118266e+117 < c < 5.2660357604755783e+182Initial program 19.4
rmApplied add-sqr-sqrt19.4
Applied *-un-lft-identity19.4
Applied times-frac19.4
Simplified19.4
Simplified12.2
rmApplied associate-*r/12.2
Simplified12.1
rmApplied div-inv12.2
if 5.2660357604755783e+182 < c Initial program 42.4
rmApplied add-sqr-sqrt42.4
Applied *-un-lft-identity42.4
Applied times-frac42.4
Simplified42.4
Simplified28.9
rmApplied associate-*r/28.9
Simplified28.9
Taylor expanded around inf 11.5
Final simplification12.7
herbie shell --seed 2020049 +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))))