\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} = -\infty:\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;\frac{b \cdot d + a \cdot c}{c \cdot c + d \cdot d} \le 1.444073714691111652490143880583541065297 \cdot 10^{307}:\\
\;\;\;\;\frac{\frac{b \cdot d + a \cdot c}{\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 r6309225 = a;
double r6309226 = c;
double r6309227 = r6309225 * r6309226;
double r6309228 = b;
double r6309229 = d;
double r6309230 = r6309228 * r6309229;
double r6309231 = r6309227 + r6309230;
double r6309232 = r6309226 * r6309226;
double r6309233 = r6309229 * r6309229;
double r6309234 = r6309232 + r6309233;
double r6309235 = r6309231 / r6309234;
return r6309235;
}
double f(double a, double b, double c, double d) {
double r6309236 = b;
double r6309237 = d;
double r6309238 = r6309236 * r6309237;
double r6309239 = a;
double r6309240 = c;
double r6309241 = r6309239 * r6309240;
double r6309242 = r6309238 + r6309241;
double r6309243 = r6309240 * r6309240;
double r6309244 = r6309237 * r6309237;
double r6309245 = r6309243 + r6309244;
double r6309246 = r6309242 / r6309245;
double r6309247 = -inf.0;
bool r6309248 = r6309246 <= r6309247;
double r6309249 = -r6309239;
double r6309250 = sqrt(r6309245);
double r6309251 = r6309249 / r6309250;
double r6309252 = 1.4440737146911117e+307;
bool r6309253 = r6309246 <= r6309252;
double r6309254 = r6309242 / r6309250;
double r6309255 = r6309254 / r6309250;
double r6309256 = r6309253 ? r6309255 : r6309251;
double r6309257 = r6309248 ? r6309251 : r6309256;
return r6309257;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.4 |
| Herbie | 24.7 |
if (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < -inf.0 or 1.4440737146911117e+307 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) Initial program 63.9
rmApplied add-sqr-sqrt63.9
Applied associate-/r*63.9
Taylor expanded around -inf 59.5
Simplified59.5
if -inf.0 < (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))) < 1.4440737146911117e+307Initial program 11.3
rmApplied add-sqr-sqrt11.3
Applied associate-/r*11.2
Final simplification24.7
herbie shell --seed 2019192
(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))))