\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.236056920632649636312988321949767458809 \cdot 10^{252}:\\
\;\;\;\;-\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le -1.972049955288829430907028189059339655129 \cdot 10^{188}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(c, d\right)} \cdot \frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}}\\
\mathbf{elif}\;c \le -9.931482377190183189903426181814662287963 \cdot 10^{103}:\\
\;\;\;\;-\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 7.28777456571337501443708414977136635674 \cdot 10^{101}:\\
\;\;\;\;\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 r78430 = a;
double r78431 = c;
double r78432 = r78430 * r78431;
double r78433 = b;
double r78434 = d;
double r78435 = r78433 * r78434;
double r78436 = r78432 + r78435;
double r78437 = r78431 * r78431;
double r78438 = r78434 * r78434;
double r78439 = r78437 + r78438;
double r78440 = r78436 / r78439;
return r78440;
}
double f(double a, double b, double c, double d) {
double r78441 = c;
double r78442 = -1.2360569206326496e+252;
bool r78443 = r78441 <= r78442;
double r78444 = a;
double r78445 = d;
double r78446 = hypot(r78441, r78445);
double r78447 = r78444 / r78446;
double r78448 = -r78447;
double r78449 = -1.9720499552888294e+188;
bool r78450 = r78441 <= r78449;
double r78451 = 1.0;
double r78452 = r78451 / r78446;
double r78453 = b;
double r78454 = r78453 * r78445;
double r78455 = fma(r78444, r78441, r78454);
double r78456 = r78446 / r78455;
double r78457 = r78451 / r78456;
double r78458 = r78452 * r78457;
double r78459 = -9.931482377190183e+103;
bool r78460 = r78441 <= r78459;
double r78461 = 7.287774565713375e+101;
bool r78462 = r78441 <= r78461;
double r78463 = r78455 / r78446;
double r78464 = r78463 / r78446;
double r78465 = r78462 ? r78464 : r78447;
double r78466 = r78460 ? r78448 : r78465;
double r78467 = r78450 ? r78458 : r78466;
double r78468 = r78443 ? r78448 : r78467;
return r78468;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 14.0 |
if c < -1.2360569206326496e+252 or -1.9720499552888294e+188 < c < -9.931482377190183e+103Initial program 36.0
rmApplied add-sqr-sqrt36.0
Applied *-un-lft-identity36.0
Applied times-frac36.0
Simplified36.0
Simplified26.2
rmApplied associate-*r/26.2
Simplified26.1
Taylor expanded around -inf 16.2
Simplified16.2
if -1.2360569206326496e+252 < c < -1.9720499552888294e+188Initial program 45.3
rmApplied add-sqr-sqrt45.3
Applied *-un-lft-identity45.3
Applied times-frac45.3
Simplified45.3
Simplified27.9
rmApplied clear-num28.0
if -9.931482377190183e+103 < c < 7.287774565713375e+101Initial program 18.5
rmApplied add-sqr-sqrt18.5
Applied *-un-lft-identity18.5
Applied times-frac18.5
Simplified18.5
Simplified11.6
rmApplied associate-*r/11.5
Simplified11.4
if 7.287774565713375e+101 < c Initial program 40.0
rmApplied add-sqr-sqrt40.0
Applied *-un-lft-identity40.0
Applied times-frac40.0
Simplified40.0
Simplified26.2
rmApplied associate-*r/26.2
Simplified26.1
Taylor expanded around inf 17.8
Final simplification14.0
herbie shell --seed 2019195 +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))))