\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -1.6322724406596933 \cdot 10^{+154}:\\
\;\;\;\;-\frac{a}{d}\\
\mathbf{elif}\;d \leq -1.548666922304495 \cdot 10^{-104}:\\
\;\;\;\;\frac{c \cdot b}{c \cdot c + d \cdot d} - \frac{a \cdot \frac{d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;d \leq 2.4346042928963056 \cdot 10^{-77}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{elif}\;d \leq 5.927595764345909 \cdot 10^{+123}:\\
\;\;\;\;\frac{c}{\sqrt{c \cdot c + d \cdot d}} \cdot \frac{b}{\sqrt{c \cdot c + d \cdot d}} - \frac{d \cdot a}{c \cdot c + d \cdot d}\\
\mathbf{else}:\\
\;\;\;\;-\frac{a}{d}\\
\end{array}(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(if (<= d -1.6322724406596933e+154)
(- (/ a d))
(if (<= d -1.548666922304495e-104)
(-
(/ (* c b) (+ (* c c) (* d d)))
(/ (* a (/ d (sqrt (+ (* c c) (* d d))))) (sqrt (+ (* c c) (* d d)))))
(if (<= d 2.4346042928963056e-77)
(- (/ b c) (/ (* d a) (+ (* c c) (* d d))))
(if (<= d 5.927595764345909e+123)
(-
(* (/ c (sqrt (+ (* c c) (* d d)))) (/ b (sqrt (+ (* c c) (* d d)))))
(/ (* d a) (+ (* c c) (* d d))))
(- (/ a d)))))))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 tmp;
if (d <= -1.6322724406596933e+154) {
tmp = -(a / d);
} else if (d <= -1.548666922304495e-104) {
tmp = ((c * b) / ((c * c) + (d * d))) - ((a * (d / sqrt((c * c) + (d * d)))) / sqrt((c * c) + (d * d)));
} else if (d <= 2.4346042928963056e-77) {
tmp = (b / c) - ((d * a) / ((c * c) + (d * d)));
} else if (d <= 5.927595764345909e+123) {
tmp = ((c / sqrt((c * c) + (d * d))) * (b / sqrt((c * c) + (d * d)))) - ((d * a) / ((c * c) + (d * d)));
} else {
tmp = -(a / d);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.0 |
|---|---|
| Target | 0.4 |
| Herbie | 13.1 |
if d < -1.6322724406596933e154 or 5.9275957643459093e123 < d Initial program 43.5
Taylor expanded around 0 14.2
Simplified14.2
if -1.6322724406596933e154 < d < -1.5486669223044951e-104Initial program 16.9
rmApplied div-sub_binary6416.9
Simplified16.9
Simplified16.9
rmApplied add-sqr-sqrt_binary6416.9
Applied associate-/r*_binary6416.8
Simplified13.4
if -1.5486669223044951e-104 < d < 2.43460429289630561e-77Initial program 21.2
rmApplied div-sub_binary6421.2
Simplified21.2
Simplified21.2
Taylor expanded around inf 10.7
if 2.43460429289630561e-77 < d < 5.9275957643459093e123Initial program 16.5
rmApplied div-sub_binary6416.5
Simplified16.5
Simplified16.5
rmApplied add-sqr-sqrt_binary6416.5
Applied times-frac_binary6415.7
Final simplification13.1
herbie shell --seed 2021110
(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))))