\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.045846669237430472528864761609559364154 \cdot 10^{123}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 8.747123436813267982750810114699097243072 \cdot 10^{191}:\\
\;\;\;\;\frac{\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{\mathsf{fma}\left(a, c, b \cdot d\right)}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(c, d\right)}{a}}\\
\end{array}double f(double a, double b, double c, double d) {
double r8259699 = a;
double r8259700 = c;
double r8259701 = r8259699 * r8259700;
double r8259702 = b;
double r8259703 = d;
double r8259704 = r8259702 * r8259703;
double r8259705 = r8259701 + r8259704;
double r8259706 = r8259700 * r8259700;
double r8259707 = r8259703 * r8259703;
double r8259708 = r8259706 + r8259707;
double r8259709 = r8259705 / r8259708;
return r8259709;
}
double f(double a, double b, double c, double d) {
double r8259710 = c;
double r8259711 = -2.0458466692374305e+123;
bool r8259712 = r8259710 <= r8259711;
double r8259713 = a;
double r8259714 = -r8259713;
double r8259715 = d;
double r8259716 = hypot(r8259710, r8259715);
double r8259717 = r8259714 / r8259716;
double r8259718 = 8.747123436813268e+191;
bool r8259719 = r8259710 <= r8259718;
double r8259720 = 1.0;
double r8259721 = b;
double r8259722 = r8259721 * r8259715;
double r8259723 = fma(r8259713, r8259710, r8259722);
double r8259724 = r8259716 / r8259723;
double r8259725 = r8259720 / r8259724;
double r8259726 = r8259725 / r8259716;
double r8259727 = r8259716 / r8259713;
double r8259728 = r8259720 / r8259727;
double r8259729 = r8259719 ? r8259726 : r8259728;
double r8259730 = r8259712 ? r8259717 : r8259729;
return r8259730;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.8 |
|---|---|
| Target | 0.4 |
| Herbie | 13.5 |
if c < -2.0458466692374305e+123Initial program 41.2
Simplified41.2
rmApplied add-sqr-sqrt41.2
Applied associate-/r*41.1
rmApplied clear-num41.2
Simplified28.4
rmApplied associate-/r/28.5
Applied associate-/r*27.8
Taylor expanded around -inf 14.5
Simplified14.5
if -2.0458466692374305e+123 < c < 8.747123436813268e+191Initial program 21.4
Simplified21.4
rmApplied add-sqr-sqrt21.4
Applied associate-/r*21.4
rmApplied clear-num21.6
Simplified13.7
rmApplied associate-/r/13.7
Applied associate-/r*13.3
if 8.747123436813268e+191 < c Initial program 43.0
Simplified43.0
rmApplied add-sqr-sqrt43.0
Applied associate-/r*43.0
rmApplied clear-num43.0
Simplified30.9
Taylor expanded around inf 13.1
Final simplification13.5
herbie shell --seed 2019174 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
: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))))