\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.2616143508082277 \cdot 10^{79} \lor \neg \left(c \le 1.03827084215452011 \cdot 10^{-35}\right):\\
\;\;\;\;\frac{\frac{b}{\frac{\mathsf{hypot}\left(c, d\right)}{c}}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)} - \frac{\frac{a}{1}}{\frac{\mathsf{hypot}\left(c, d\right)}{\frac{d}{\mathsf{hypot}\left(c, d\right)}}}\\
\end{array}double code(double a, double b, double c, double d) {
return (((b * c) - (a * d)) / ((c * c) + (d * d)));
}
double code(double a, double b, double c, double d) {
double temp;
if (((c <= -2.2616143508082277e+79) || !(c <= 1.0382708421545201e-35))) {
temp = (((b / (hypot(c, d) / c)) / hypot(c, d)) - (((a * d) / hypot(c, d)) / hypot(c, d)));
} else {
temp = ((((b * c) / hypot(c, d)) / hypot(c, d)) - ((a / 1.0) / (hypot(c, d) / (d / hypot(c, d)))));
}
return temp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.5 |
|---|---|
| Target | 0.4 |
| Herbie | 4.8 |
if c < -2.2616143508082277e+79 or 1.0382708421545201e-35 < c Initial program 33.6
rmApplied add-sqr-sqrt33.6
Applied *-un-lft-identity33.6
Applied times-frac33.6
Simplified33.6
Simplified23.3
rmApplied associate-*r/23.2
Simplified23.2
rmApplied div-sub23.2
Applied div-sub23.2
rmApplied associate-/l*7.8
if -2.2616143508082277e+79 < c < 1.0382708421545201e-35Initial program 19.6
rmApplied add-sqr-sqrt19.6
Applied *-un-lft-identity19.6
Applied times-frac19.6
Simplified19.6
Simplified11.8
rmApplied associate-*r/11.7
Simplified11.7
rmApplied div-sub11.7
Applied div-sub11.7
rmApplied *-un-lft-identity11.7
Applied times-frac1.7
Applied associate-/l*1.9
Final simplification4.8
herbie shell --seed 2020060 +o rules:numerics
(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))))