\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{a \cdot d}{c}\\
\mathbf{if}\;c \leq -2.330818031561063 \cdot 10^{+164}:\\
\;\;\;\;\frac{t_0 - b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{\frac{c \cdot b - a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{if}\;c \leq -1.3684374183631767 \cdot 10^{-60}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;c \leq 5.36355955475327 \cdot 10^{-73}:\\
\;\;\;\;\frac{c \cdot b}{d \cdot d} - \frac{a}{d}\\
\mathbf{elif}\;c \leq 2.389280118127783 \cdot 10^{+109}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b - t_0}{\mathsf{hypot}\left(d, c\right)}\\
\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 (/ (* a d) c)))
(if (<= c -2.330818031561063e+164)
(/ (- t_0 b) (hypot d c))
(let* ((t_1 (/ (/ (- (* c b) (* a d)) (hypot d c)) (hypot d c))))
(if (<= c -1.3684374183631767e-60)
t_1
(if (<= c 5.36355955475327e-73)
(- (/ (* c b) (* d d)) (/ a d))
(if (<= c 2.389280118127783e+109)
t_1
(/ (- b t_0) (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 = (a * d) / c;
double tmp;
if (c <= -2.330818031561063e+164) {
tmp = (t_0 - b) / hypot(d, c);
} else {
double t_1 = (((c * b) - (a * d)) / hypot(d, c)) / hypot(d, c);
double tmp_1;
if (c <= -1.3684374183631767e-60) {
tmp_1 = t_1;
} else if (c <= 5.36355955475327e-73) {
tmp_1 = ((c * b) / (d * d)) - (a / d);
} else if (c <= 2.389280118127783e+109) {
tmp_1 = t_1;
} else {
tmp_1 = (b - t_0) / hypot(d, c);
}
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 | 12.8 |
if c < -2.33081803156106311e164Initial program 44.6
Simplified44.6
Applied add-sqr-sqrt_binary6444.6
Applied *-un-lft-identity_binary6444.6
Applied times-frac_binary6444.6
Simplified44.6
Simplified29.8
Applied associate-*l/_binary6429.8
Simplified29.8
Taylor expanded in c around -inf 11.1
if -2.33081803156106311e164 < c < -1.3684374183631767e-60 or 5.3635595547532703e-73 < c < 2.3892801181277829e109Initial program 18.8
Simplified18.8
Applied add-sqr-sqrt_binary6418.8
Applied *-un-lft-identity_binary6418.8
Applied times-frac_binary6418.9
Simplified18.9
Simplified13.1
Applied associate-*l/_binary6413.0
Simplified13.0
Applied *-un-lft-identity_binary6413.0
if -1.3684374183631767e-60 < c < 5.3635595547532703e-73Initial program 20.5
Simplified20.5
Applied add-sqr-sqrt_binary6420.5
Applied *-un-lft-identity_binary6420.5
Applied times-frac_binary6420.5
Simplified20.5
Simplified12.3
Applied clear-num_binary6412.4
Taylor expanded in d around inf 12.9
Simplified12.9
if 2.3892801181277829e109 < c Initial program 41.2
Simplified41.2
Applied add-sqr-sqrt_binary6441.2
Applied *-un-lft-identity_binary6441.2
Applied times-frac_binary6441.2
Simplified41.2
Simplified27.1
Applied associate-*l/_binary6427.0
Simplified27.0
Taylor expanded in c around inf 13.4
Final simplification12.8
herbie shell --seed 2022072
(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))))