\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.086126503497258 \cdot 10^{+188}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 6.204871618360054 \cdot 10^{+176}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, d \cdot b\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r4281043 = a;
double r4281044 = c;
double r4281045 = r4281043 * r4281044;
double r4281046 = b;
double r4281047 = d;
double r4281048 = r4281046 * r4281047;
double r4281049 = r4281045 + r4281048;
double r4281050 = r4281044 * r4281044;
double r4281051 = r4281047 * r4281047;
double r4281052 = r4281050 + r4281051;
double r4281053 = r4281049 / r4281052;
return r4281053;
}
double f(double a, double b, double c, double d) {
double r4281054 = c;
double r4281055 = -5.086126503497258e+188;
bool r4281056 = r4281054 <= r4281055;
double r4281057 = a;
double r4281058 = -r4281057;
double r4281059 = d;
double r4281060 = hypot(r4281059, r4281054);
double r4281061 = r4281058 / r4281060;
double r4281062 = 6.204871618360054e+176;
bool r4281063 = r4281054 <= r4281062;
double r4281064 = b;
double r4281065 = r4281059 * r4281064;
double r4281066 = fma(r4281057, r4281054, r4281065);
double r4281067 = r4281066 / r4281060;
double r4281068 = r4281067 / r4281060;
double r4281069 = r4281057 / r4281060;
double r4281070 = r4281063 ? r4281068 : r4281069;
double r4281071 = r4281056 ? r4281061 : r4281070;
return r4281071;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.6 |
|---|---|
| Target | 0.4 |
| Herbie | 12.9 |
if c < -5.086126503497258e+188Initial program 41.2
Simplified41.2
rmApplied add-sqr-sqrt41.2
Applied associate-/r*41.2
rmApplied clear-num41.2
Simplified29.6
rmApplied associate-/r*29.0
Simplified29.0
Taylor expanded around -inf 12.0
Simplified12.0
if -5.086126503497258e+188 < c < 6.204871618360054e+176Initial program 20.9
Simplified20.9
rmApplied add-sqr-sqrt20.9
Applied associate-/r*20.8
rmApplied clear-num21.1
Simplified13.6
rmApplied associate-/r*13.1
Simplified13.0
if 6.204871618360054e+176 < c Initial program 44.6
Simplified44.6
rmApplied add-sqr-sqrt44.6
Applied associate-/r*44.6
rmApplied clear-num44.6
Simplified31.9
rmApplied associate-/r*31.4
Simplified31.4
Taylor expanded around inf 12.5
Final simplification12.9
herbie shell --seed 2019162 +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))))