\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.15437883947267018 \cdot 10^{126}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 7.6439338361981289 \cdot 10^{118}:\\
\;\;\;\;\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 r123808 = a;
double r123809 = c;
double r123810 = r123808 * r123809;
double r123811 = b;
double r123812 = d;
double r123813 = r123811 * r123812;
double r123814 = r123810 + r123813;
double r123815 = r123809 * r123809;
double r123816 = r123812 * r123812;
double r123817 = r123815 + r123816;
double r123818 = r123814 / r123817;
return r123818;
}
double f(double a, double b, double c, double d) {
double r123819 = c;
double r123820 = -4.15437883947267e+126;
bool r123821 = r123819 <= r123820;
double r123822 = -1.0;
double r123823 = a;
double r123824 = r123822 * r123823;
double r123825 = d;
double r123826 = hypot(r123819, r123825);
double r123827 = 1.0;
double r123828 = r123826 * r123827;
double r123829 = r123824 / r123828;
double r123830 = 7.643933836198129e+118;
bool r123831 = r123819 <= r123830;
double r123832 = b;
double r123833 = r123832 * r123825;
double r123834 = fma(r123823, r123819, r123833);
double r123835 = r123834 / r123826;
double r123836 = r123835 / r123828;
double r123837 = r123823 / r123828;
double r123838 = r123831 ? r123836 : r123837;
double r123839 = r123821 ? r123829 : r123838;
return r123839;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.1 |
|---|---|
| Target | 0.5 |
| Herbie | 13.0 |
if c < -4.15437883947267e+126Initial program 41.5
rmApplied add-sqr-sqrt41.5
Applied *-un-lft-identity41.5
Applied times-frac41.5
Simplified41.5
Simplified27.5
rmApplied associate-*r/27.5
Simplified27.4
Taylor expanded around -inf 15.5
if -4.15437883947267e+126 < c < 7.643933836198129e+118Initial program 18.5
rmApplied add-sqr-sqrt18.5
Applied *-un-lft-identity18.5
Applied times-frac18.5
Simplified18.5
Simplified11.9
rmApplied associate-*r/11.9
Simplified11.8
if 7.643933836198129e+118 < c Initial program 42.4
rmApplied add-sqr-sqrt42.4
Applied *-un-lft-identity42.4
Applied times-frac42.4
Simplified42.4
Simplified28.5
rmApplied associate-*r/28.5
Simplified28.4
Taylor expanded around inf 15.6
Final simplification13.0
herbie shell --seed 2020083 +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))))