\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.2360569206326496 \cdot 10^{252}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le -4.92872222777350137 \cdot 10^{189}:\\
\;\;\;\;\frac{\sqrt[3]{{\left(\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}\right)}^{3}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le -9.9314823771901832 \cdot 10^{103}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 7.287774565713375 \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 r67446 = a;
double r67447 = c;
double r67448 = r67446 * r67447;
double r67449 = b;
double r67450 = d;
double r67451 = r67449 * r67450;
double r67452 = r67448 + r67451;
double r67453 = r67447 * r67447;
double r67454 = r67450 * r67450;
double r67455 = r67453 + r67454;
double r67456 = r67452 / r67455;
return r67456;
}
double f(double a, double b, double c, double d) {
double r67457 = c;
double r67458 = -1.2360569206326496e+252;
bool r67459 = r67457 <= r67458;
double r67460 = a;
double r67461 = -r67460;
double r67462 = d;
double r67463 = hypot(r67457, r67462);
double r67464 = r67461 / r67463;
double r67465 = -4.928722227773501e+189;
bool r67466 = r67457 <= r67465;
double r67467 = b;
double r67468 = r67467 * r67462;
double r67469 = fma(r67460, r67457, r67468);
double r67470 = r67469 / r67463;
double r67471 = 3.0;
double r67472 = pow(r67470, r67471);
double r67473 = cbrt(r67472);
double r67474 = r67473 / r67463;
double r67475 = -9.931482377190183e+103;
bool r67476 = r67457 <= r67475;
double r67477 = 7.287774565713375e+101;
bool r67478 = r67457 <= r67477;
double r67479 = r67470 / r67463;
double r67480 = r67460 / r67463;
double r67481 = r67478 ? r67479 : r67480;
double r67482 = r67476 ? r67464 : r67481;
double r67483 = r67466 ? r67474 : r67482;
double r67484 = r67459 ? r67464 : r67483;
return r67484;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 14.1 |
if c < -1.2360569206326496e+252 or -4.928722227773501e+189 < c < -9.931482377190183e+103Initial program 36.1
rmApplied add-sqr-sqrt36.1
Applied *-un-lft-identity36.1
Applied times-frac36.1
Simplified36.1
Simplified26.0
rmApplied *-un-lft-identity26.0
Applied associate-*l*26.0
Simplified26.0
Taylor expanded around -inf 16.2
Simplified16.2
if -1.2360569206326496e+252 < c < -4.928722227773501e+189Initial program 45.4
rmApplied add-sqr-sqrt45.4
Applied *-un-lft-identity45.4
Applied times-frac45.4
Simplified45.4
Simplified28.3
rmApplied *-un-lft-identity28.3
Applied associate-*l*28.3
Simplified28.3
rmApplied add-cbrt-cube28.6
Simplified28.6
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 *-un-lft-identity11.6
Applied associate-*l*11.6
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 *-un-lft-identity26.2
Applied associate-*l*26.2
Simplified26.1
Taylor expanded around inf 17.8
Final simplification14.1
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))))