\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -9.727239627244697 \cdot 10^{203}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 8.7515444588077776 \cdot 10^{105}:\\
\;\;\;\;\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 r111362 = a;
double r111363 = c;
double r111364 = r111362 * r111363;
double r111365 = b;
double r111366 = d;
double r111367 = r111365 * r111366;
double r111368 = r111364 + r111367;
double r111369 = r111363 * r111363;
double r111370 = r111366 * r111366;
double r111371 = r111369 + r111370;
double r111372 = r111368 / r111371;
return r111372;
}
double f(double a, double b, double c, double d) {
double r111373 = c;
double r111374 = -9.727239627244697e+203;
bool r111375 = r111373 <= r111374;
double r111376 = -1.0;
double r111377 = a;
double r111378 = r111376 * r111377;
double r111379 = d;
double r111380 = hypot(r111373, r111379);
double r111381 = 1.0;
double r111382 = r111380 * r111381;
double r111383 = r111378 / r111382;
double r111384 = 8.751544458807778e+105;
bool r111385 = r111373 <= r111384;
double r111386 = b;
double r111387 = r111386 * r111379;
double r111388 = fma(r111377, r111373, r111387);
double r111389 = r111388 / r111380;
double r111390 = r111389 / r111382;
double r111391 = r111377 / r111382;
double r111392 = r111385 ? r111390 : r111391;
double r111393 = r111375 ? r111383 : r111392;
return r111393;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 13.3 |
if c < -9.727239627244697e+203Initial program 42.0
rmApplied add-sqr-sqrt42.0
Applied *-un-lft-identity42.0
Applied times-frac42.0
Simplified42.0
Simplified31.1
rmApplied associate-*r/31.1
Simplified31.0
Taylor expanded around -inf 11.0
if -9.727239627244697e+203 < c < 8.751544458807778e+105Initial program 21.0
rmApplied add-sqr-sqrt21.0
Applied *-un-lft-identity21.0
Applied times-frac21.0
Simplified21.0
Simplified13.0
rmApplied associate-*r/13.0
Simplified12.9
if 8.751544458807778e+105 < c Initial program 39.0
rmApplied add-sqr-sqrt39.0
Applied *-un-lft-identity39.0
Applied times-frac39.0
Simplified39.0
Simplified25.2
rmApplied associate-*r/25.2
Simplified25.2
Taylor expanded around inf 16.3
Final simplification13.3
herbie shell --seed 2020024 +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))))