\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -4.78970221325173 \cdot 10^{+151}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 7.209078410675665 \cdot 10^{+132}:\\
\;\;\;\;\frac{\frac{b \cdot c}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)} - \frac{\frac{d \cdot a}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(d, c\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r4086287 = b;
double r4086288 = c;
double r4086289 = r4086287 * r4086288;
double r4086290 = a;
double r4086291 = d;
double r4086292 = r4086290 * r4086291;
double r4086293 = r4086289 - r4086292;
double r4086294 = r4086288 * r4086288;
double r4086295 = r4086291 * r4086291;
double r4086296 = r4086294 + r4086295;
double r4086297 = r4086293 / r4086296;
return r4086297;
}
double f(double a, double b, double c, double d) {
double r4086298 = c;
double r4086299 = -4.78970221325173e+151;
bool r4086300 = r4086298 <= r4086299;
double r4086301 = b;
double r4086302 = -r4086301;
double r4086303 = d;
double r4086304 = hypot(r4086303, r4086298);
double r4086305 = r4086302 / r4086304;
double r4086306 = 7.209078410675665e+132;
bool r4086307 = r4086298 <= r4086306;
double r4086308 = r4086301 * r4086298;
double r4086309 = r4086308 / r4086304;
double r4086310 = r4086309 / r4086304;
double r4086311 = a;
double r4086312 = r4086303 * r4086311;
double r4086313 = r4086312 / r4086304;
double r4086314 = r4086313 / r4086304;
double r4086315 = r4086310 - r4086314;
double r4086316 = r4086301 / r4086304;
double r4086317 = r4086307 ? r4086315 : r4086316;
double r4086318 = r4086300 ? r4086305 : r4086317;
return r4086318;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.7 |
|---|---|
| Target | 0.4 |
| Herbie | 12.3 |
if c < -4.78970221325173e+151Initial program 44.1
Simplified44.1
rmApplied add-sqr-sqrt44.1
Applied associate-/r*44.1
rmApplied fma-udef44.1
Applied hypot-def44.1
Taylor expanded around -inf 13.0
Simplified13.0
if -4.78970221325173e+151 < c < 7.209078410675665e+132Initial program 18.7
Simplified18.7
rmApplied add-sqr-sqrt18.8
Applied associate-/r*18.7
rmApplied fma-udef18.7
Applied hypot-def18.6
rmApplied fma-udef18.6
Applied hypot-def11.7
rmApplied div-sub11.7
Applied div-sub11.7
if 7.209078410675665e+132 < c Initial program 41.8
Simplified41.8
rmApplied add-sqr-sqrt41.8
Applied associate-/r*41.8
rmApplied fma-udef41.8
Applied hypot-def41.8
Taylor expanded around inf 14.4
Final simplification12.3
herbie shell --seed 2019168 +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))))