\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.9328947580125936 \cdot 10^{148}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 1.1661264907998782 \cdot 10^{265}:\\
\;\;\;\;\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 r123568 = a;
double r123569 = c;
double r123570 = r123568 * r123569;
double r123571 = b;
double r123572 = d;
double r123573 = r123571 * r123572;
double r123574 = r123570 + r123573;
double r123575 = r123569 * r123569;
double r123576 = r123572 * r123572;
double r123577 = r123575 + r123576;
double r123578 = r123574 / r123577;
return r123578;
}
double f(double a, double b, double c, double d) {
double r123579 = c;
double r123580 = -3.9328947580125936e+148;
bool r123581 = r123579 <= r123580;
double r123582 = -1.0;
double r123583 = a;
double r123584 = r123582 * r123583;
double r123585 = d;
double r123586 = hypot(r123579, r123585);
double r123587 = 1.0;
double r123588 = r123586 * r123587;
double r123589 = r123584 / r123588;
double r123590 = 1.1661264907998782e+265;
bool r123591 = r123579 <= r123590;
double r123592 = b;
double r123593 = r123592 * r123585;
double r123594 = fma(r123583, r123579, r123593);
double r123595 = r123594 / r123586;
double r123596 = r123595 / r123588;
double r123597 = r123583 / r123588;
double r123598 = r123591 ? r123596 : r123597;
double r123599 = r123581 ? r123589 : r123598;
return r123599;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.7 |
|---|---|
| Target | 0.4 |
| Herbie | 14.3 |
if c < -3.9328947580125936e+148Initial program 43.4
rmApplied add-sqr-sqrt43.4
Applied *-un-lft-identity43.4
Applied times-frac43.4
Simplified43.4
Simplified28.0
rmApplied associate-*r/27.9
Simplified27.9
Taylor expanded around -inf 13.2
if -3.9328947580125936e+148 < c < 1.1661264907998782e+265Initial program 23.2
rmApplied add-sqr-sqrt23.2
Applied *-un-lft-identity23.2
Applied times-frac23.2
Simplified23.2
Simplified15.0
rmApplied associate-*r/14.9
Simplified14.8
if 1.1661264907998782e+265 < c Initial program 38.9
rmApplied add-sqr-sqrt38.9
Applied *-un-lft-identity38.9
Applied times-frac38.9
Simplified38.9
Simplified32.6
rmApplied associate-*r/32.6
Simplified32.6
Taylor expanded around inf 8.2
Final simplification14.3
herbie shell --seed 2020034 +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))))