\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -3.2283116114628037 \cdot 10^{+100}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -2.2844571867045313 \cdot 10^{-93}:\\
\;\;\;\;\frac{\frac{c \cdot b - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{elif}\;d \leq 9.170406126705686 \cdot 10^{-109}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\
\mathbf{elif}\;d \leq 3.6607070884127416 \cdot 10^{+145}:\\
\;\;\;\;\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 -3.2283116114628037e+100)
(- (/ (* c b) (* d d)) (/ a d))
(if (<= d -2.2844571867045313e-93)
(/
(/ (- (* c b) (* d a)) (sqrt (+ (* d d) (* c c))))
(sqrt (+ (* d d) (* c c))))
(if (<= d 9.170406126705686e-109)
(- (/ b c) (/ (* d a) (* c c)))
(if (<= d 3.6607070884127416e+145)
(/
(/ (- (* 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 <= -3.2283116114628037e+100) {
tmp = ((c * b) / (d * d)) - (a / d);
} else if (d <= -2.2844571867045313e-93) {
tmp = (((c * b) - (d * a)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
} else if (d <= 9.170406126705686e-109) {
tmp = (b / c) - ((d * a) / (c * c));
} else if (d <= 3.6607070884127416e+145) {
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 | 26.2 |
|---|---|
| Target | 0.4 |
| Herbie | 14.8 |
if d < -3.22831161146280375e100Initial program 39.8
Taylor expanded around 0 15.1
Simplified15.1
if -3.22831161146280375e100 < d < -2.28445718670453135e-93 or 9.17040612670568637e-109 < d < 3.6607070884127416e145Initial program 17.2
rmApplied add-sqr-sqrt_binary64_78217.2
Applied associate-/r*_binary64_70417.1
Simplified17.1
if -2.28445718670453135e-93 < d < 9.17040612670568637e-109Initial program 20.9
Taylor expanded around inf 11.5
Simplified11.5
if 3.6607070884127416e145 < d Initial program 44.0
Taylor expanded around 0 15.6
Simplified15.6
Final simplification14.8
herbie shell --seed 2021043
(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))))