\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.0757333618448412 \cdot 10^{183}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 4.35189948757554904 \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 r112479 = a;
double r112480 = c;
double r112481 = r112479 * r112480;
double r112482 = b;
double r112483 = d;
double r112484 = r112482 * r112483;
double r112485 = r112481 + r112484;
double r112486 = r112480 * r112480;
double r112487 = r112483 * r112483;
double r112488 = r112486 + r112487;
double r112489 = r112485 / r112488;
return r112489;
}
double f(double a, double b, double c, double d) {
double r112490 = c;
double r112491 = -3.075733361844841e+183;
bool r112492 = r112490 <= r112491;
double r112493 = -1.0;
double r112494 = a;
double r112495 = r112493 * r112494;
double r112496 = d;
double r112497 = hypot(r112490, r112496);
double r112498 = 1.0;
double r112499 = r112497 * r112498;
double r112500 = r112495 / r112499;
double r112501 = 4.351899487575549e+105;
bool r112502 = r112490 <= r112501;
double r112503 = b;
double r112504 = r112503 * r112496;
double r112505 = fma(r112494, r112490, r112504);
double r112506 = r112505 / r112497;
double r112507 = r112506 / r112499;
double r112508 = r112494 / r112499;
double r112509 = r112502 ? r112507 : r112508;
double r112510 = r112492 ? r112500 : r112509;
return r112510;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.5 |
|---|---|
| Target | 0.4 |
| Herbie | 13.3 |
if c < -3.075733361844841e+183Initial program 44.4
rmApplied add-sqr-sqrt44.4
Applied *-un-lft-identity44.4
Applied times-frac44.4
Simplified44.4
Simplified29.2
rmApplied associate-*r/29.2
Simplified29.2
Taylor expanded around -inf 12.0
if -3.075733361844841e+183 < c < 4.351899487575549e+105Initial program 20.3
rmApplied add-sqr-sqrt20.3
Applied *-un-lft-identity20.3
Applied times-frac20.4
Simplified20.4
Simplified12.7
rmApplied associate-*r/12.7
Simplified12.6
if 4.351899487575549e+105 < c Initial program 41.0
rmApplied add-sqr-sqrt41.0
Applied *-un-lft-identity41.0
Applied times-frac41.0
Simplified41.0
Simplified28.8
rmApplied associate-*r/28.8
Simplified28.7
Taylor expanded around inf 16.6
Final simplification13.3
herbie shell --seed 2020018 +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))))