\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \leq -3.2563987087522574 \cdot 10^{+81}:\\
\;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \frac{a}{d}\\
\mathbf{elif}\;d \leq -8.232708701844971 \cdot 10^{-48}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{elif}\;d \leq 1.8192329406445362 \cdot 10^{-149}:\\
\;\;\;\;\frac{b}{c} - \frac{d \cdot a}{c \cdot c}\\
\mathbf{elif}\;d \leq 2.0139063475555305 \cdot 10^{+69}:\\
\;\;\;\;\frac{\frac{b \cdot c - d \cdot a}{\sqrt{d \cdot d + c \cdot c}}}{\sqrt{d \cdot d + c \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\frac{d \cdot d}{c}} - \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.2563987087522574e+81)
(- (/ b (/ (* d d) c)) (/ a d))
(if (<= d -8.232708701844971e-48)
(/
(/ (- (* b c) (* d a)) (sqrt (+ (* d d) (* c c))))
(sqrt (+ (* d d) (* c c))))
(if (<= d 1.8192329406445362e-149)
(- (/ b c) (/ (* d a) (* c c)))
(if (<= d 2.0139063475555305e+69)
(/
(/ (- (* b c) (* d a)) (sqrt (+ (* d d) (* c c))))
(sqrt (+ (* d d) (* c c))))
(- (/ b (/ (* d d) 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.2563987087522574e+81) {
tmp = (b / ((d * d) / c)) - (a / d);
} else if (d <= -8.232708701844971e-48) {
tmp = (((b * c) - (d * a)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
} else if (d <= 1.8192329406445362e-149) {
tmp = (b / c) - ((d * a) / (c * c));
} else if (d <= 2.0139063475555305e+69) {
tmp = (((b * c) - (d * a)) / sqrt((d * d) + (c * c))) / sqrt((d * d) + (c * c));
} else {
tmp = (b / ((d * d) / c)) - (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.5 |
| Herbie | 14.8 |
if d < -3.256398708752257e81 or 2.01390634755553049e69 < d Initial program 37.9
rmApplied add-sqr-sqrt_binary64_487437.9
Applied *-un-lft-identity_binary64_485237.9
Applied times-frac_binary64_485837.9
Simplified37.9
Taylor expanded around 0 17.5
Simplified16.9
if -3.256398708752257e81 < d < -8.23270870184497108e-48 or 1.8192329406445362e-149 < d < 2.01390634755553049e69Initial program 14.7
rmApplied add-sqr-sqrt_binary64_487414.7
Applied associate-/r*_binary64_479614.6
if -8.23270870184497108e-48 < d < 1.8192329406445362e-149Initial program 21.8
Taylor expanded around inf 12.3
Simplified12.3
Final simplification14.8
herbie shell --seed 2021044
(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))))