\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}
\begin{array}{l}
t_0 := b \cdot c - a \cdot d\\
t_1 := \frac{t_0}{c \cdot c + d \cdot d}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\frac{b}{c}\\
\mathbf{elif}\;t_1 \leq 7.916655966912562 \cdot 10^{+295}:\\
\;\;\;\;\frac{\frac{t_0}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\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))) (t_1 (/ t_0 (+ (* c c) (* d d)))))
(if (<= t_1 (- INFINITY))
(/ b c)
(if (<= t_1 7.916655966912562e+295)
(/ (/ t_0 (hypot d c)) (hypot d 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);
double t_1 = t_0 / ((c * c) + (d * d));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = b / c;
} else if (t_1 <= 7.916655966912562e+295) {
tmp = (t_0 / hypot(d, c)) / hypot(d, 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 | 26.1 |
|---|---|
| Target | 0.5 |
| Herbie | 10.4 |
if (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < -inf.0Initial program 64.0
Simplified64.0
Taylor expanded in c around inf 36.8
if -inf.0 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) < 7.9166559669125623e295Initial program 11.7
Simplified11.7
Applied add-sqr-sqrt_binary6411.7
Applied *-un-lft-identity_binary6411.7
Applied times-frac_binary6411.7
Simplified11.7
Simplified0.7
Applied associate-*l/_binary640.6
Simplified0.6
if 7.9166559669125623e295 < (/.f64 (-.f64 (*.f64 b c) (*.f64 a d)) (+.f64 (*.f64 c c) (*.f64 d d))) Initial program 63.1
Simplified63.1
Taylor expanded in c around 0 35.6
Simplified35.6
Final simplification10.4
herbie shell --seed 2022081
(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))))