\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -2.6657023148269232 \cdot 10^{+54}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -1.2031460365109471 \cdot 10^{-102}:\\
\;\;\;\;\frac{c \cdot b - d \cdot a}{d \cdot d + c \cdot c}\\
\mathbf{elif}\;d \leq 5.980746905707731 \cdot 10^{-154}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\
\mathbf{elif}\;d \leq 1.4163261492702185 \cdot 10^{+153}:\\
\;\;\;\;\frac{\frac{c \cdot b - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\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 -2.6657023148269232e+54)
(- (/ (* c b) (* d d)) (/ a d))
(if (<= d -1.2031460365109471e-102)
(/ (- (* c b) (* d a)) (+ (* d d) (* c c)))
(if (<= d 5.980746905707731e-154)
(- (/ b c) (/ (* d a) (* c c)))
(if (<= d 1.4163261492702185e+153)
(/
(/ (- (* c b) (* d a)) (sqrt (+ (* d d) (* c c))))
(sqrt (+ (* d d) (* c c))))
(- (/ 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 <= -2.6657023148269232e+54) {
tmp = ((c * b) / (d * d)) - (a / d);
} else if (d <= -1.2031460365109471e-102) {
tmp = ((c * b) - (d * a)) / ((d * d) + (c * c));
} else if (d <= 5.980746905707731e-154) {
tmp = (b / c) - ((d * a) / (c * c));
} else if (d <= 1.4163261492702185e+153) {
tmp = (((c * b) - (d * a)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
} else {
tmp = -(a / d);
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.8 |
|---|---|
| Target | 0.3 |
| Herbie | 14.4 |
if d < -2.6657023148269232e54Initial program 36.9
Taylor expanded around 0 16.8
Simplified16.8
if -2.6657023148269232e54 < d < -1.2031460365109471e-102Initial program 14.5
if -1.2031460365109471e-102 < d < 5.9807469057077313e-154Initial program 23.2
Taylor expanded around inf 10.7
Simplified10.7
if 5.9807469057077313e-154 < d < 1.41632614927021847e153Initial program 17.2
rmApplied add-sqr-sqrt_binary64_316917.2
Applied associate-/r*_binary64_309117.1
if 1.41632614927021847e153 < d Initial program 43.0
Taylor expanded around 0 12.8
Simplified12.8
Final simplification14.4
herbie shell --seed 2021024
(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))))