\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} = -\infty \lor \neg \left(\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d} \le 5.085210929411777452302962127466150247434 \cdot 10^{305}\right):\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b \cdot c - a \cdot d\right) \cdot \frac{1}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r123391 = b;
double r123392 = c;
double r123393 = r123391 * r123392;
double r123394 = a;
double r123395 = d;
double r123396 = r123394 * r123395;
double r123397 = r123393 - r123396;
double r123398 = r123392 * r123392;
double r123399 = r123395 * r123395;
double r123400 = r123398 + r123399;
double r123401 = r123397 / r123400;
return r123401;
}
double f(double a, double b, double c, double d) {
double r123402 = b;
double r123403 = c;
double r123404 = r123402 * r123403;
double r123405 = a;
double r123406 = d;
double r123407 = r123405 * r123406;
double r123408 = r123404 - r123407;
double r123409 = r123403 * r123403;
double r123410 = r123406 * r123406;
double r123411 = r123409 + r123410;
double r123412 = r123408 / r123411;
double r123413 = -inf.0;
bool r123414 = r123412 <= r123413;
double r123415 = 5.0852109294117775e+305;
bool r123416 = r123412 <= r123415;
double r123417 = !r123416;
bool r123418 = r123414 || r123417;
double r123419 = -r123405;
double r123420 = sqrt(r123411);
double r123421 = r123419 / r123420;
double r123422 = 1.0;
double r123423 = r123422 / r123420;
double r123424 = r123408 * r123423;
double r123425 = r123424 / r123420;
double r123426 = r123418 ? r123421 : r123425;
return r123426;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 25.0 |
if (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < -inf.0 or 5.0852109294117775e+305 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) Initial program 63.9
rmApplied add-sqr-sqrt63.9
Applied associate-/r*63.9
Taylor expanded around 0 59.5
Simplified59.5
if -inf.0 < (/ (- (* b c) (* a d)) (+ (* c c) (* d d))) < 5.0852109294117775e+305Initial program 11.8
rmApplied add-sqr-sqrt11.8
Applied associate-/r*11.7
rmApplied div-inv11.8
Final simplification25.0
herbie shell --seed 2019351
(FPCore (a b c d)
:name "Complex division, imag part"
:precision binary64
:herbie-target
(if (< (fabs d) (fabs c)) (/ (- b (* a (/ d c))) (+ c (* d (/ d c)))) (/ (+ (- a) (* b (/ c d))) (+ d (* c (/ c d)))))
(/ (- (* b c) (* a d)) (+ (* c c) (* d d))))