\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d} \le 3.29064580259523516 \cdot 10^{293}:\\
\;\;\;\;\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d} \cdot \sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-1 \cdot a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r115953 = a;
double r115954 = c;
double r115955 = r115953 * r115954;
double r115956 = b;
double r115957 = d;
double r115958 = r115956 * r115957;
double r115959 = r115955 + r115958;
double r115960 = r115954 * r115954;
double r115961 = r115957 * r115957;
double r115962 = r115960 + r115961;
double r115963 = r115959 / r115962;
return r115963;
}
double f(double a, double b, double c, double d) {
double r115964 = a;
double r115965 = c;
double r115966 = r115964 * r115965;
double r115967 = b;
double r115968 = d;
double r115969 = r115967 * r115968;
double r115970 = r115966 + r115969;
double r115971 = r115965 * r115965;
double r115972 = r115968 * r115968;
double r115973 = r115971 + r115972;
double r115974 = r115970 / r115973;
double r115975 = 3.290645802595235e+293;
bool r115976 = r115974 <= r115975;
double r115977 = sqrt(r115973);
double r115978 = r115977 * r115977;
double r115979 = r115970 / r115978;
double r115980 = -1.0;
double r115981 = r115980 * r115964;
double r115982 = r115981 / r115977;
double r115983 = r115976 ? r115979 : r115982;
return r115983;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.4 |
|---|---|
| Target | 0.5 |
| Herbie | 25.7 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 3.290645802595235e+293Initial program 14.4
rmApplied add-sqr-sqrt14.4
if 3.290645802595235e+293 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.2
rmApplied add-sqr-sqrt63.2
Applied associate-/r*63.2
Taylor expanded around -inf 60.2
Final simplification25.7
herbie shell --seed 2020046
(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))))