\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 2.12596178726660471909605146790118406087 \cdot 10^{114}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r81322 = a;
double r81323 = c;
double r81324 = r81322 * r81323;
double r81325 = b;
double r81326 = d;
double r81327 = r81325 * r81326;
double r81328 = r81324 + r81327;
double r81329 = r81323 * r81323;
double r81330 = r81326 * r81326;
double r81331 = r81329 + r81330;
double r81332 = r81328 / r81331;
return r81332;
}
double f(double a, double b, double c, double d) {
double r81333 = d;
double r81334 = 2.1259617872666047e+114;
bool r81335 = r81333 <= r81334;
double r81336 = a;
double r81337 = c;
double r81338 = b;
double r81339 = r81338 * r81333;
double r81340 = fma(r81336, r81337, r81339);
double r81341 = hypot(r81337, r81333);
double r81342 = r81340 / r81341;
double r81343 = r81342 / r81341;
double r81344 = r81338 / r81341;
double r81345 = r81335 ? r81343 : r81344;
return r81345;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.8 |
|---|---|
| Target | 0.3 |
| Herbie | 14.7 |
if d < 2.1259617872666047e+114Initial program 23.0
rmApplied add-sqr-sqrt23.0
Applied *-un-lft-identity23.0
Applied times-frac23.0
Simplified23.0
Simplified14.7
rmApplied associate-*r/14.7
Simplified14.6
if 2.1259617872666047e+114 < d Initial program 40.4
rmApplied add-sqr-sqrt40.4
Applied *-un-lft-identity40.4
Applied times-frac40.4
Simplified40.4
Simplified27.2
rmApplied associate-*r/27.1
Simplified27.1
Taylor expanded around 0 15.2
Final simplification14.7
herbie shell --seed 2019323 +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))))