\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le 3.67504458165974214 \cdot 10^{89}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\sqrt{c \cdot c + d \cdot d}}}{\sqrt{c \cdot c + d \cdot d}}\\
\mathbf{else}:\\
\;\;\;\;\frac{-a}{\sqrt{c \cdot c + d \cdot d}}\\
\end{array}double f(double a, double b, double c, double d) {
double r122101 = b;
double r122102 = c;
double r122103 = r122101 * r122102;
double r122104 = a;
double r122105 = d;
double r122106 = r122104 * r122105;
double r122107 = r122103 - r122106;
double r122108 = r122102 * r122102;
double r122109 = r122105 * r122105;
double r122110 = r122108 + r122109;
double r122111 = r122107 / r122110;
return r122111;
}
double f(double a, double b, double c, double d) {
double r122112 = d;
double r122113 = 3.675044581659742e+89;
bool r122114 = r122112 <= r122113;
double r122115 = b;
double r122116 = c;
double r122117 = r122115 * r122116;
double r122118 = a;
double r122119 = r122118 * r122112;
double r122120 = r122117 - r122119;
double r122121 = r122116 * r122116;
double r122122 = r122112 * r122112;
double r122123 = r122121 + r122122;
double r122124 = sqrt(r122123);
double r122125 = r122120 / r122124;
double r122126 = r122125 / r122124;
double r122127 = -r122118;
double r122128 = r122127 / r122124;
double r122129 = r122114 ? r122126 : r122128;
return r122129;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.7 |
|---|---|
| Target | 0.5 |
| Herbie | 26.5 |
if d < 3.675044581659742e+89Initial program 23.7
rmApplied add-sqr-sqrt23.7
Applied associate-/r*23.6
if 3.675044581659742e+89 < d Initial program 38.6
rmApplied add-sqr-sqrt38.7
Applied associate-/r*38.6
Taylor expanded around 0 38.0
Simplified38.0
Final simplification26.5
herbie shell --seed 2020042
(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))))