\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.15167370780975257 \cdot 10^{185}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 1.4191655951273249 \cdot 10^{147}:\\
\;\;\;\;\frac{\left(a \cdot c + b \cdot d\right) \cdot \frac{1}{\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 r120434 = a;
double r120435 = c;
double r120436 = r120434 * r120435;
double r120437 = b;
double r120438 = d;
double r120439 = r120437 * r120438;
double r120440 = r120436 + r120439;
double r120441 = r120435 * r120435;
double r120442 = r120438 * r120438;
double r120443 = r120441 + r120442;
double r120444 = r120440 / r120443;
return r120444;
}
double f(double a, double b, double c, double d) {
double r120445 = c;
double r120446 = -2.1516737078097526e+185;
bool r120447 = r120445 <= r120446;
double r120448 = -1.0;
double r120449 = a;
double r120450 = r120448 * r120449;
double r120451 = d;
double r120452 = hypot(r120445, r120451);
double r120453 = 1.0;
double r120454 = r120452 * r120453;
double r120455 = r120450 / r120454;
double r120456 = 1.4191655951273249e+147;
bool r120457 = r120445 <= r120456;
double r120458 = r120449 * r120445;
double r120459 = b;
double r120460 = r120459 * r120451;
double r120461 = r120458 + r120460;
double r120462 = r120453 / r120452;
double r120463 = r120461 * r120462;
double r120464 = r120463 / r120454;
double r120465 = r120449 / r120454;
double r120466 = r120457 ? r120464 : r120465;
double r120467 = r120447 ? r120455 : r120466;
return r120467;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.4 |
|---|---|
| Target | 0.4 |
| Herbie | 13.2 |
if c < -2.1516737078097526e+185Initial program 43.5
rmApplied add-sqr-sqrt43.5
Applied *-un-lft-identity43.5
Applied times-frac43.5
Simplified43.5
Simplified30.2
rmApplied associate-*r/30.1
Simplified30.1
Taylor expanded around -inf 12.0
if -2.1516737078097526e+185 < c < 1.4191655951273249e+147Initial program 20.6
rmApplied add-sqr-sqrt20.6
Applied *-un-lft-identity20.6
Applied times-frac20.6
Simplified20.6
Simplified13.2
rmApplied associate-*r/13.1
Simplified13.1
rmApplied fma-udef13.1
rmApplied div-inv13.1
if 1.4191655951273249e+147 < c Initial program 44.8
rmApplied add-sqr-sqrt44.8
Applied *-un-lft-identity44.8
Applied times-frac44.8
Simplified44.8
Simplified27.8
rmApplied associate-*r/27.8
Simplified27.7
Taylor expanded around inf 14.7
Final simplification13.2
herbie shell --seed 2020062 +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))))