\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 1.937670017341036534919481795915749319496 \cdot 10^{62}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}} \cdot \left(b \cdot c - d \cdot a\right)}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{\mathsf{fma}\left(d, d, c \cdot c\right)}}\\
\end{array}double f(double a, double b, double c, double d) {
double r5460110 = b;
double r5460111 = c;
double r5460112 = r5460110 * r5460111;
double r5460113 = a;
double r5460114 = d;
double r5460115 = r5460113 * r5460114;
double r5460116 = r5460112 - r5460115;
double r5460117 = r5460111 * r5460111;
double r5460118 = r5460114 * r5460114;
double r5460119 = r5460117 + r5460118;
double r5460120 = r5460116 / r5460119;
return r5460120;
}
double f(double a, double b, double c, double d) {
double r5460121 = d;
double r5460122 = 1.9376700173410365e+62;
bool r5460123 = r5460121 <= r5460122;
double r5460124 = 1.0;
double r5460125 = c;
double r5460126 = r5460125 * r5460125;
double r5460127 = fma(r5460121, r5460121, r5460126);
double r5460128 = sqrt(r5460127);
double r5460129 = r5460124 / r5460128;
double r5460130 = b;
double r5460131 = r5460130 * r5460125;
double r5460132 = a;
double r5460133 = r5460121 * r5460132;
double r5460134 = r5460131 - r5460133;
double r5460135 = r5460129 * r5460134;
double r5460136 = r5460135 / r5460128;
double r5460137 = -r5460132;
double r5460138 = r5460137 / r5460128;
double r5460139 = r5460123 ? r5460136 : r5460138;
return r5460139;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 26.3 |
if d < 1.9376700173410365e+62Initial program 23.4
Simplified23.4
rmApplied add-sqr-sqrt23.4
Applied associate-/r*23.3
rmApplied div-inv23.4
if 1.9376700173410365e+62 < d Initial program 37.3
Simplified37.3
rmApplied add-sqr-sqrt37.3
Applied associate-/r*37.2
Taylor expanded around 0 37.5
Simplified37.5
Final simplification26.3
herbie shell --seed 2019170 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, imag part"
: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))))