\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -1.75773301102882159 \cdot 10^{162}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 9.4134247976417832 \cdot 10^{156}:\\
\;\;\;\;\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 r96345 = a;
double r96346 = c;
double r96347 = r96345 * r96346;
double r96348 = b;
double r96349 = d;
double r96350 = r96348 * r96349;
double r96351 = r96347 + r96350;
double r96352 = r96346 * r96346;
double r96353 = r96349 * r96349;
double r96354 = r96352 + r96353;
double r96355 = r96351 / r96354;
return r96355;
}
double f(double a, double b, double c, double d) {
double r96356 = c;
double r96357 = -1.7577330110288216e+162;
bool r96358 = r96356 <= r96357;
double r96359 = -1.0;
double r96360 = a;
double r96361 = r96359 * r96360;
double r96362 = d;
double r96363 = hypot(r96356, r96362);
double r96364 = 1.0;
double r96365 = r96363 * r96364;
double r96366 = r96361 / r96365;
double r96367 = 9.413424797641783e+156;
bool r96368 = r96356 <= r96367;
double r96369 = b;
double r96370 = r96369 * r96362;
double r96371 = fma(r96360, r96356, r96370);
double r96372 = r96371 / r96363;
double r96373 = r96372 / r96365;
double r96374 = r96360 / r96365;
double r96375 = r96368 ? r96373 : r96374;
double r96376 = r96358 ? r96366 : r96375;
return r96376;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.4 |
| Herbie | 12.9 |
if c < -1.7577330110288216e+162Initial program 45.1
rmApplied add-sqr-sqrt45.1
Applied *-un-lft-identity45.1
Applied times-frac45.1
Simplified45.1
Simplified29.0
rmApplied associate-*r/29.0
Simplified29.0
Taylor expanded around -inf 13.4
if -1.7577330110288216e+162 < c < 9.413424797641783e+156Initial program 20.0
rmApplied add-sqr-sqrt20.0
Applied *-un-lft-identity20.0
Applied times-frac20.0
Simplified20.0
Simplified12.9
rmApplied associate-*r/12.9
Simplified12.8
if 9.413424797641783e+156 < c Initial program 44.2
rmApplied add-sqr-sqrt44.2
Applied *-un-lft-identity44.2
Applied times-frac44.2
Simplified44.2
Simplified28.8
rmApplied associate-*r/28.8
Simplified28.8
Taylor expanded around inf 13.4
Final simplification12.9
herbie shell --seed 2020060 +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))))