\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.54617340469776 \cdot 10^{+94}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;c \le 1.9951833757328278 \cdot 10^{+142}:\\
\;\;\;\;\frac{\left(b \cdot c - d \cdot a\right) \cdot \frac{1}{\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 r3132487 = b;
double r3132488 = c;
double r3132489 = r3132487 * r3132488;
double r3132490 = a;
double r3132491 = d;
double r3132492 = r3132490 * r3132491;
double r3132493 = r3132489 - r3132492;
double r3132494 = r3132488 * r3132488;
double r3132495 = r3132491 * r3132491;
double r3132496 = r3132494 + r3132495;
double r3132497 = r3132493 / r3132496;
return r3132497;
}
double f(double a, double b, double c, double d) {
double r3132498 = c;
double r3132499 = -3.54617340469776e+94;
bool r3132500 = r3132498 <= r3132499;
double r3132501 = b;
double r3132502 = -r3132501;
double r3132503 = d;
double r3132504 = hypot(r3132503, r3132498);
double r3132505 = r3132502 / r3132504;
double r3132506 = 1.9951833757328278e+142;
bool r3132507 = r3132498 <= r3132506;
double r3132508 = r3132501 * r3132498;
double r3132509 = a;
double r3132510 = r3132503 * r3132509;
double r3132511 = r3132508 - r3132510;
double r3132512 = 1.0;
double r3132513 = r3132512 / r3132504;
double r3132514 = r3132511 * r3132513;
double r3132515 = r3132514 / r3132504;
double r3132516 = r3132501 / r3132504;
double r3132517 = r3132507 ? r3132515 : r3132516;
double r3132518 = r3132500 ? r3132505 : r3132517;
return r3132518;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.5 |
|---|---|
| Target | 0.5 |
| Herbie | 12.9 |
if c < -3.54617340469776e+94Initial program 38.3
Simplified38.3
rmApplied add-sqr-sqrt38.3
Applied associate-/r*38.3
rmApplied fma-udef38.3
Applied hypot-def38.3
Taylor expanded around -inf 16.2
Simplified16.2
if -3.54617340469776e+94 < c < 1.9951833757328278e+142Initial program 18.6
Simplified18.6
rmApplied add-sqr-sqrt18.6
Applied associate-/r*18.5
rmApplied fma-udef18.5
Applied hypot-def18.5
rmApplied *-un-lft-identity18.5
Applied associate-/r*18.5
Simplified11.4
rmApplied div-inv11.5
if 1.9951833757328278e+142 < c Initial program 41.4
Simplified41.4
rmApplied add-sqr-sqrt41.4
Applied associate-/r*41.4
rmApplied fma-udef41.4
Applied hypot-def41.4
Taylor expanded around inf 14.8
Final simplification12.9
herbie shell --seed 2019135 +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))))