\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -1.0880969741880458 \cdot 10^{+46}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{d}}\\
\mathbf{elif}\;c \leq -2.5124826680120464 \cdot 10^{-157}:\\
\;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \leq 1.4117694234224077 \cdot 10^{-177}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 3.948083792625873 \cdot 10^{+21}:\\
\;\;\;\;\frac{\frac{c \cdot b - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \leq 8.313098602456845 \cdot 10^{+41}:\\
\;\;\;\;-\frac{a}{d}\\
\mathbf{elif}\;c \leq 1.324093728718764 \cdot 10^{+134}:\\
\;\;\;\;\frac{b - \frac{a \cdot d}{c}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c} - \frac{a}{\frac{c \cdot c}{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 (<= c -1.0880969741880458e+46)
(- (/ b c) (/ a (/ (* c c) d)))
(if (<= c -2.5124826680120464e-157)
(/
(/ (- (* c b) (* a d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= c 1.4117694234224077e-177)
(- (/ (* c b) (* d d)) (/ a d))
(if (<= c 3.948083792625873e+21)
(/
(/ (- (* c b) (* a d)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= c 8.313098602456845e+41)
(- (/ a d))
(if (<= c 1.324093728718764e+134)
(/ (- b (/ (* a d) c)) (sqrt (+ (* c c) (* d d))))
(- (/ b c) (/ a (/ (* c c) 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 (c <= -1.0880969741880458e+46) {
tmp = (b / c) - (a / ((c * c) / d));
} else if (c <= -2.5124826680120464e-157) {
tmp = (((c * b) - (a * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (c <= 1.4117694234224077e-177) {
tmp = ((c * b) / (d * d)) - (a / d);
} else if (c <= 3.948083792625873e+21) {
tmp = (((c * b) - (a * d)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (c <= 8.313098602456845e+41) {
tmp = -(a / d);
} else if (c <= 1.324093728718764e+134) {
tmp = (b - ((a * d) / c)) / sqrt((c * c) + (d * d));
} else {
tmp = (b / c) - (a / ((c * c) / d));
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.9 |
|---|---|
| Target | 0.4 |
| Herbie | 15.5 |
if c < -1.08809697418804577e46 or 1.324093728718764e134 < c Initial program 39.0
rmApplied add-sqr-sqrt_binary6439.0
Applied associate-/r*_binary6439.0
Simplified39.0
Taylor expanded around inf 17.4
Simplified16.5
if -1.08809697418804577e46 < c < -2.51248266801204636e-157 or 1.4117694234224077e-177 < c < 3948083792625873190000Initial program 15.1
rmApplied add-sqr-sqrt_binary6415.1
Applied associate-/r*_binary6415.1
if -2.51248266801204636e-157 < c < 1.4117694234224077e-177Initial program 26.2
rmApplied add-sqr-sqrt_binary6426.2
Applied associate-/r*_binary6426.1
Simplified26.1
Taylor expanded around 0 26.2
Simplified26.2
Taylor expanded around 0 10.2
Simplified10.2
if 3948083792625873190000 < c < 8.3130986024568448e41Initial program 16.1
Taylor expanded around 0 44.1
Simplified44.1
if 8.3130986024568448e41 < c < 1.324093728718764e134Initial program 22.4
rmApplied add-sqr-sqrt_binary6422.4
Applied associate-/r*_binary6422.4
Simplified22.4
Taylor expanded around inf 20.8
Final simplification15.5
herbie shell --seed 2021174
(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))))