\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 r4858290 = a;
double r4858291 = c;
double r4858292 = r4858290 * r4858291;
double r4858293 = b;
double r4858294 = d;
double r4858295 = r4858293 * r4858294;
double r4858296 = r4858292 + r4858295;
double r4858297 = r4858291 * r4858291;
double r4858298 = r4858294 * r4858294;
double r4858299 = r4858297 + r4858298;
double r4858300 = r4858296 / r4858299;
return r4858300;
}
double f(double a, double b, double c, double d) {
double r4858301 = c;
double r4858302 = -5.086126503497258e+188;
bool r4858303 = r4858301 <= r4858302;
double r4858304 = a;
double r4858305 = -r4858304;
double r4858306 = d;
double r4858307 = hypot(r4858306, r4858301);
double r4858308 = r4858305 / r4858307;
double r4858309 = 6.204871618360054e+176;
bool r4858310 = r4858301 <= r4858309;
double r4858311 = b;
double r4858312 = r4858306 * r4858311;
double r4858313 = fma(r4858304, r4858301, r4858312);
double r4858314 = r4858313 / r4858307;
double r4858315 = r4858314 / r4858307;
double r4858316 = r4858304 / r4858307;
double r4858317 = r4858310 ? r4858315 : r4858316;
double r4858318 = r4858303 ? r4858308 : r4858317;
return r4858318;
}




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))))