\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.184102796584514783395314393474998984417 \cdot 10^{103}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 3.447690369320142988028236121143935476164 \cdot 10^{145}:\\
\;\;\;\;\frac{\mathsf{fma}\left(a, c, b \cdot d\right) \cdot \frac{1}{\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 r132976 = a;
double r132977 = c;
double r132978 = r132976 * r132977;
double r132979 = b;
double r132980 = d;
double r132981 = r132979 * r132980;
double r132982 = r132978 + r132981;
double r132983 = r132977 * r132977;
double r132984 = r132980 * r132980;
double r132985 = r132983 + r132984;
double r132986 = r132982 / r132985;
return r132986;
}
double f(double a, double b, double c, double d) {
double r132987 = c;
double r132988 = -1.1841027965845148e+103;
bool r132989 = r132987 <= r132988;
double r132990 = -1.0;
double r132991 = a;
double r132992 = r132990 * r132991;
double r132993 = d;
double r132994 = hypot(r132987, r132993);
double r132995 = 1.0;
double r132996 = r132994 * r132995;
double r132997 = r132992 / r132996;
double r132998 = 3.447690369320143e+145;
bool r132999 = r132987 <= r132998;
double r133000 = b;
double r133001 = r133000 * r132993;
double r133002 = fma(r132991, r132987, r133001);
double r133003 = r132995 / r132994;
double r133004 = r133002 * r133003;
double r133005 = r133004 / r132996;
double r133006 = r132991 / r132996;
double r133007 = r132999 ? r133005 : r133006;
double r133008 = r132989 ? r132997 : r133007;
return r133008;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.7 |
|---|---|
| Target | 0.5 |
| Herbie | 12.8 |
if c < -1.1841027965845148e+103Initial program 39.1
rmApplied add-sqr-sqrt39.1
Applied *-un-lft-identity39.1
Applied times-frac39.1
Simplified39.1
Simplified26.5
rmApplied associate-*r/26.5
Simplified26.4
Taylor expanded around -inf 16.8
if -1.1841027965845148e+103 < c < 3.447690369320143e+145Initial program 18.3
rmApplied add-sqr-sqrt18.3
Applied *-un-lft-identity18.3
Applied times-frac18.3
Simplified18.3
Simplified11.4
rmApplied associate-*r/11.4
Simplified11.3
rmApplied div-inv11.4
if 3.447690369320143e+145 < c Initial program 44.8
rmApplied add-sqr-sqrt44.8
Applied *-un-lft-identity44.8
Applied times-frac44.8
Simplified44.8
Simplified28.7
rmApplied associate-*r/28.7
Simplified28.6
Taylor expanded around inf 14.2
Final simplification12.8
herbie shell --seed 2019356 +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))))