\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{b}{c} - \frac{a}{c} \cdot \frac{d}{c}\\
\mathbf{if}\;c \leq -1.3940742026862542 \cdot 10^{+133}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \sqrt{d \cdot d + c \cdot c}\\
t_2 := \frac{\frac{c \cdot b - a \cdot d}{t_1}}{t_1}\\
\mathbf{if}\;c \leq -1.3557623343064346 \cdot 10^{-10}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;c \leq 2.046408208770978 \cdot 10^{-175}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 1.5513558310683366 \cdot 10^{+151}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\end{array}
(FPCore (a b c d) :precision binary64 (/ (- (* b c) (* a d)) (+ (* c c) (* d d))))
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (/ b c) (* (/ a c) (/ d c)))))
(if (<= c -1.3940742026862542e+133)
t_0
(let* ((t_1 (sqrt (+ (* d d) (* c c))))
(t_2 (/ (/ (- (* c b) (* a d)) t_1) t_1)))
(if (<= c -1.3557623343064346e-10)
t_2
(if (<= c 2.046408208770978e-175)
(- (/ (* c b) (* d d)) (/ a d))
(if (<= c 1.5513558310683366e+151) t_2 t_0)))))))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 t_0 = (b / c) - ((a / c) * (d / c));
double tmp;
if (c <= -1.3940742026862542e+133) {
tmp = t_0;
} else {
double t_1 = sqrt((d * d) + (c * c));
double t_2 = (((c * b) - (a * d)) / t_1) / t_1;
double tmp_1;
if (c <= -1.3557623343064346e-10) {
tmp_1 = t_2;
} else if (c <= 2.046408208770978e-175) {
tmp_1 = ((c * b) / (d * d)) - (a / d);
} else if (c <= 1.5513558310683366e+151) {
tmp_1 = t_2;
} else {
tmp_1 = t_0;
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 13.7 |
if c < -1.39407420268625422e133 or 1.5513558310683366e151 < c Initial program 43.3
Taylor expanded around inf 15.9
Simplified15.9
rmApplied times-frac_binary647.5
if -1.39407420268625422e133 < c < -1.3557623343064346e-10 or 2.0464082087709779e-175 < c < 1.5513558310683366e151Initial program 17.5
rmApplied add-sqr-sqrt_binary6417.5
Applied associate-/r*_binary6417.4
Simplified17.4
if -1.3557623343064346e-10 < c < 2.0464082087709779e-175Initial program 21.5
Taylor expanded around 0 14.8
Simplified14.8
Final simplification13.7
herbie shell --seed 2021205
(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))))