\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.28633112851537097840983624634443392687 \cdot 10^{162}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 1.543067909128725187583327964894972109151 \cdot 10^{185}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\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 r116474 = a;
double r116475 = c;
double r116476 = r116474 * r116475;
double r116477 = b;
double r116478 = d;
double r116479 = r116477 * r116478;
double r116480 = r116476 + r116479;
double r116481 = r116475 * r116475;
double r116482 = r116478 * r116478;
double r116483 = r116481 + r116482;
double r116484 = r116480 / r116483;
return r116484;
}
double f(double a, double b, double c, double d) {
double r116485 = c;
double r116486 = -5.286331128515371e+162;
bool r116487 = r116485 <= r116486;
double r116488 = a;
double r116489 = -r116488;
double r116490 = d;
double r116491 = hypot(r116485, r116490);
double r116492 = r116489 / r116491;
double r116493 = 1.5430679091287252e+185;
bool r116494 = r116485 <= r116493;
double r116495 = b;
double r116496 = r116495 * r116490;
double r116497 = fma(r116488, r116485, r116496);
double r116498 = r116497 / r116491;
double r116499 = r116498 / r116491;
double r116500 = r116488 / r116491;
double r116501 = r116494 ? r116499 : r116500;
double r116502 = r116487 ? r116492 : r116501;
return r116502;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.5 |
| Herbie | 12.6 |
if c < -5.286331128515371e+162Initial program 44.6
rmApplied add-sqr-sqrt44.6
Applied *-un-lft-identity44.6
Applied times-frac44.6
Simplified44.6
Simplified29.7
rmApplied *-un-lft-identity29.7
Applied *-un-lft-identity29.7
Applied times-frac29.7
Applied associate-*l*29.7
Simplified29.7
Taylor expanded around -inf 12.7
Simplified12.7
if -5.286331128515371e+162 < c < 1.5430679091287252e+185Initial program 20.4
rmApplied add-sqr-sqrt20.4
Applied *-un-lft-identity20.4
Applied times-frac20.4
Simplified20.4
Simplified12.7
rmApplied *-un-lft-identity12.7
Applied *-un-lft-identity12.7
Applied times-frac12.7
Applied associate-*l*12.7
Simplified12.6
if 1.5430679091287252e+185 < c Initial program 44.3
rmApplied add-sqr-sqrt44.3
Applied *-un-lft-identity44.3
Applied times-frac44.3
Simplified44.3
Simplified30.5
rmApplied *-un-lft-identity30.5
Applied *-un-lft-identity30.5
Applied times-frac30.5
Applied associate-*l*30.5
Simplified30.4
Taylor expanded around inf 12.8
Final simplification12.6
herbie shell --seed 2019325 +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))))