\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -6.4031543623445702 \cdot 10^{213}:\\
\;\;\;\;\frac{-1 \cdot b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 7.51325573675878584 \cdot 10^{136}:\\
\;\;\;\;\frac{\frac{b \cdot c - a \cdot d}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r109340 = b;
double r109341 = c;
double r109342 = r109340 * r109341;
double r109343 = a;
double r109344 = d;
double r109345 = r109343 * r109344;
double r109346 = r109342 - r109345;
double r109347 = r109341 * r109341;
double r109348 = r109344 * r109344;
double r109349 = r109347 + r109348;
double r109350 = r109346 / r109349;
return r109350;
}
double f(double a, double b, double c, double d) {
double r109351 = c;
double r109352 = -6.40315436234457e+213;
bool r109353 = r109351 <= r109352;
double r109354 = -1.0;
double r109355 = b;
double r109356 = r109354 * r109355;
double r109357 = d;
double r109358 = hypot(r109351, r109357);
double r109359 = r109356 / r109358;
double r109360 = 7.513255736758786e+136;
bool r109361 = r109351 <= r109360;
double r109362 = r109355 * r109351;
double r109363 = a;
double r109364 = r109363 * r109357;
double r109365 = r109362 - r109364;
double r109366 = r109365 / r109358;
double r109367 = r109366 / r109358;
double r109368 = r109355 / r109358;
double r109369 = r109361 ? r109367 : r109368;
double r109370 = r109353 ? r109359 : r109369;
return r109370;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 26.8 |
|---|---|
| Target | 0.4 |
| Herbie | 13.2 |
if c < -6.40315436234457e+213Initial program 41.9
rmApplied add-sqr-sqrt41.9
Applied *-un-lft-identity41.9
Applied times-frac41.9
Simplified41.9
Simplified31.5
rmApplied associate-*r/31.5
Simplified31.5
Taylor expanded around -inf 10.7
if -6.40315436234457e+213 < c < 7.513255736758786e+136Initial program 21.9
rmApplied add-sqr-sqrt21.9
Applied *-un-lft-identity21.9
Applied times-frac21.9
Simplified21.9
Simplified13.4
rmApplied associate-*r/13.3
Simplified13.2
if 7.513255736758786e+136 < c Initial program 43.5
rmApplied add-sqr-sqrt43.5
Applied *-un-lft-identity43.5
Applied times-frac43.5
Simplified43.5
Simplified28.7
rmApplied associate-*r/28.7
Simplified28.7
Taylor expanded around inf 14.3
Final simplification13.2
herbie shell --seed 2020034 +o rules:numerics
(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))))