\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 4.737122355537421671534518653596175011386 \cdot 10^{285}:\\
\;\;\;\;\frac{\frac{a \cdot c + b \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r95222 = a;
double r95223 = c;
double r95224 = r95222 * r95223;
double r95225 = b;
double r95226 = d;
double r95227 = r95225 * r95226;
double r95228 = r95224 + r95227;
double r95229 = r95223 * r95223;
double r95230 = r95226 * r95226;
double r95231 = r95229 + r95230;
double r95232 = r95228 / r95231;
return r95232;
}
double f(double a, double b, double c, double d) {
double r95233 = a;
double r95234 = c;
double r95235 = r95233 * r95234;
double r95236 = b;
double r95237 = d;
double r95238 = r95236 * r95237;
double r95239 = r95235 + r95238;
double r95240 = r95234 * r95234;
double r95241 = r95237 * r95237;
double r95242 = r95240 + r95241;
double r95243 = r95239 / r95242;
double r95244 = 4.7371223555374217e+285;
bool r95245 = r95243 <= r95244;
double r95246 = sqrt(r95242);
double r95247 = r95239 / r95246;
double r95248 = r95247 / r95246;
double r95249 = -r95233;
double r95250 = r95249 / r95246;
double r95251 = r95245 ? r95248 : r95250;
return r95251;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.3 |
| Herbie | 25.1 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 4.7371223555374217e+285Initial program 13.7
rmApplied add-sqr-sqrt13.7
Applied associate-/r*13.6
if 4.7371223555374217e+285 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 62.6
rmApplied add-sqr-sqrt62.7
Applied associate-/r*62.6
Taylor expanded around -inf 60.2
Simplified60.2
Final simplification25.1
herbie shell --seed 2019323
(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))))