\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \leq -5.716459959379754 \cdot 10^{+151}:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;c \leq -4.319804439634208 \cdot 10^{+68}:\\
\;\;\;\;\frac{\frac{d \cdot a}{c} - b}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \leq -1.4292144434333795 \cdot 10^{-145}:\\
\;\;\;\;\frac{\frac{c \cdot b - d \cdot a}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{elif}\;c \leq 3.49936390175958 \cdot 10^{-78}:\\
\;\;\;\;\frac{c \cdot b}{{d}^{2}} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 1.596706401112998 \cdot 10^{+146}:\\
\;\;\;\;\frac{c \cdot b}{{d}^{2} + {c}^{2}} - \frac{d \cdot a}{{d}^{2} + {c}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{c}\\
\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 -5.716459959379754e+151)
(/ b c)
(if (<= c -4.319804439634208e+68)
(/ (- (/ (* d a) c) b) (sqrt (+ (* c c) (* d d))))
(if (<= c -1.4292144434333795e-145)
(/
(/ (- (* c b) (* d a)) (sqrt (+ (* c c) (* d d))))
(sqrt (+ (* c c) (* d d))))
(if (<= c 3.49936390175958e-78)
(- (/ (* c b) (pow d 2.0)) (/ a d))
(if (<= c 1.596706401112998e+146)
(-
(/ (* c b) (+ (pow d 2.0) (pow c 2.0)))
(/ (* d a) (+ (pow d 2.0) (pow c 2.0))))
(/ b c)))))))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 <= -5.716459959379754e+151) {
tmp = b / c;
} else if (c <= -4.319804439634208e+68) {
tmp = (((d * a) / c) - b) / sqrt((c * c) + (d * d));
} else if (c <= -1.4292144434333795e-145) {
tmp = (((c * b) - (d * a)) / sqrt((c * c) + (d * d))) / sqrt((c * c) + (d * d));
} else if (c <= 3.49936390175958e-78) {
tmp = ((c * b) / pow(d, 2.0)) - (a / d);
} else if (c <= 1.596706401112998e+146) {
tmp = ((c * b) / (pow(d, 2.0) + pow(c, 2.0))) - ((d * a) / (pow(d, 2.0) + pow(c, 2.0)));
} else {
tmp = b / c;
}
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.6 |
if c < -5.71645995937975394e151 or 1.596706401112998e146 < c Initial program 44.5
Taylor expanded around inf 14.9
if -5.71645995937975394e151 < c < -4.3198044396342084e68Initial program 24.1
rmApplied add-sqr-sqrt_binary64_351024.1
Applied associate-/r*_binary64_343224.0
Simplified24.0
Taylor expanded around -inf 17.8
if -4.3198044396342084e68 < c < -1.4292144434333795e-145Initial program 15.6
rmApplied add-sqr-sqrt_binary64_351015.6
Applied associate-/r*_binary64_343215.5
Simplified15.5
if -1.4292144434333795e-145 < c < 3.4993639017595799e-78Initial program 22.4
Taylor expanded around 0 11.4
if 3.4993639017595799e-78 < c < 1.596706401112998e146Initial program 17.1
Taylor expanded around 0 17.1
Final simplification14.6
herbie shell --seed 2021045
(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))))