\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := \frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_0 \leq 1.8860901164613604 \cdot 10^{+292}:\\
\;\;\;\;\frac{\frac{b \cdot c}{\mathsf{hypot}\left(d, c\right)} - \frac{a \cdot d}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;t_0 \leq \infty:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{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
(let* ((t_0 (/ (- (* b c) (* a d)) (+ (* c c) (* d d)))))
(if (<= t_0 1.8860901164613604e+292)
(/ (- (/ (* b c) (hypot d c)) (/ (* a d) (hypot d c))) (hypot d c))
(if (<= t_0 INFINITY) (/ b c) (/ (- a) 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 t_0 = ((b * c) - (a * d)) / ((c * c) + (d * d));
double tmp;
if (t_0 <= 1.8860901164613604e+292) {
tmp = (((b * c) / hypot(d, c)) - ((a * d) / hypot(d, c))) / hypot(d, c);
} else if (t_0 <= ((double) INFINITY)) {
tmp = b / c;
} else {
tmp = -a / d;
}
return tmp;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.6 |
|---|---|
| Target | 0.5 |
| Herbie | 10.8 |
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 1.88609011646136039e292Initial program 13.9
Simplified13.9
Applied add-sqr-sqrt_binary6413.9
Applied *-un-lft-identity_binary6413.9
Applied times-frac_binary6413.9
Simplified13.9
Simplified2.8
Applied associate-*r/_binary642.8
Applied sub-neg_binary642.8
Applied distribute-rgt-in_binary642.8
Simplified2.7
Simplified2.7
if 1.88609011646136039e292 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < +inf.0Initial program 58.5
Simplified58.5
Taylor expanded in c around inf 37.8
if +inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 64.0
Simplified64.0
Taylor expanded in c around 0 36.3
Final simplification10.8
herbie shell --seed 2021313
(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))))