\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{c \cdot b}{d}\\
\mathbf{if}\;d \leq -1.0001347671923885 \cdot 10^{+180}:\\
\;\;\;\;\frac{a - t_0}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := c \cdot b - d \cdot a\\
t_2 := \frac{\frac{t_1}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;d \leq -1.0719267080027835 \cdot 10^{-77}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_3 := \frac{b}{c} - \frac{d \cdot a}{{c}^{2}}\\
\mathbf{if}\;d \leq -2.3624307415395805 \cdot 10^{-197}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;d \leq -7.746052639847127 \cdot 10^{-223}:\\
\;\;\;\;\frac{\frac{1}{\mathsf{hypot}\left(d, c\right)}}{\frac{\mathsf{hypot}\left(d, c\right)}{t_1}}\\
\mathbf{elif}\;d \leq -8.168380286508774 \cdot 10^{-280}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;d \leq 2.6508181390370694 \cdot 10^{+133}:\\
\;\;\;\;t_2\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0 - a}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}\\
\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 (/ (* c b) d)))
(if (<= d -1.0001347671923885e+180)
(/ (- a t_0) (hypot d c))
(let* ((t_1 (- (* c b) (* d a)))
(t_2 (/ (/ t_1 (hypot d c)) (hypot d c))))
(if (<= d -1.0719267080027835e-77)
t_2
(let* ((t_3 (- (/ b c) (/ (* d a) (pow c 2.0)))))
(if (<= d -2.3624307415395805e-197)
t_3
(if (<= d -7.746052639847127e-223)
(/ (/ 1.0 (hypot d c)) (/ (hypot d c) t_1))
(if (<= d -8.168380286508774e-280)
t_3
(if (<= d 2.6508181390370694e+133)
t_2
(/ (- t_0 a) (hypot d 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 t_0 = (c * b) / d;
double tmp;
if (d <= -1.0001347671923885e+180) {
tmp = (a - t_0) / hypot(d, c);
} else {
double t_1 = (c * b) - (d * a);
double t_2 = (t_1 / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (d <= -1.0719267080027835e-77) {
tmp_1 = t_2;
} else {
double t_3 = (b / c) - ((d * a) / pow(c, 2.0));
double tmp_2;
if (d <= -2.3624307415395805e-197) {
tmp_2 = t_3;
} else if (d <= -7.746052639847127e-223) {
tmp_2 = (1.0 / hypot(d, c)) / (hypot(d, c) / t_1);
} else if (d <= -8.168380286508774e-280) {
tmp_2 = t_3;
} else if (d <= 2.6508181390370694e+133) {
tmp_2 = t_2;
} else {
tmp_2 = (t_0 - a) / hypot(d, c);
}
tmp_1 = tmp_2;
}
tmp = tmp_1;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 24.3 |
|---|---|
| Target | 0.5 |
| Herbie | 11.7 |
if d < -1.00013476719238851e180Initial program 42.5
Simplified42.5
Applied add-sqr-sqrt_binary6442.5
Applied *-un-lft-identity_binary6442.5
Applied times-frac_binary6442.5
Simplified42.5
Simplified28.4
Applied associate-*l/_binary6428.4
Simplified28.4
Taylor expanded in d around -inf 9.6
if -1.00013476719238851e180 < d < -1.0719267080027835e-77 or -8.1683802865087739e-280 < d < 2.6508181390370694e133Initial program 19.1
Simplified19.1
Applied add-sqr-sqrt_binary6419.1
Applied *-un-lft-identity_binary6419.1
Applied times-frac_binary6419.1
Simplified19.1
Simplified12.0
Applied associate-*l/_binary6411.9
Simplified11.9
Applied pow1_binary6411.9
if -1.0719267080027835e-77 < d < -2.3624307415395805e-197 or -7.74605263984712723e-223 < d < -8.1683802865087739e-280Initial program 16.0
Simplified16.0
Taylor expanded in c around inf 12.8
if -2.3624307415395805e-197 < d < -7.74605263984712723e-223Initial program 20.0
Simplified20.0
Applied add-sqr-sqrt_binary6420.0
Applied *-un-lft-identity_binary6420.0
Applied times-frac_binary6420.0
Simplified20.0
Simplified8.8
Applied associate-*l/_binary648.7
Simplified8.7
Applied clear-num_binary648.8
Applied associate-/r/_binary648.8
Applied associate-/l*_binary648.8
if 2.6508181390370694e133 < d Initial program 40.7
Simplified40.7
Applied add-sqr-sqrt_binary6440.7
Applied *-un-lft-identity_binary6440.7
Applied times-frac_binary6440.7
Simplified40.7
Simplified26.1
Applied associate-*l/_binary6426.0
Simplified26.0
Taylor expanded in c around 0 11.9
Final simplification11.7
herbie shell --seed 2022068
(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))))