\frac{b \cdot c - a \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -5.58972528481860216307208015835708105017 \cdot 10^{116}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 4.790153388469599519369386020665188076147 \cdot 10^{114}:\\
\;\;\;\;\frac{\frac{b \cdot c}{\mathsf{hypot}\left(c, d\right)} - \frac{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 r5439330 = b;
double r5439331 = c;
double r5439332 = r5439330 * r5439331;
double r5439333 = a;
double r5439334 = d;
double r5439335 = r5439333 * r5439334;
double r5439336 = r5439332 - r5439335;
double r5439337 = r5439331 * r5439331;
double r5439338 = r5439334 * r5439334;
double r5439339 = r5439337 + r5439338;
double r5439340 = r5439336 / r5439339;
return r5439340;
}
double f(double a, double b, double c, double d) {
double r5439341 = c;
double r5439342 = -5.589725284818602e+116;
bool r5439343 = r5439341 <= r5439342;
double r5439344 = b;
double r5439345 = -r5439344;
double r5439346 = d;
double r5439347 = hypot(r5439341, r5439346);
double r5439348 = r5439345 / r5439347;
double r5439349 = 4.7901533884695995e+114;
bool r5439350 = r5439341 <= r5439349;
double r5439351 = r5439344 * r5439341;
double r5439352 = r5439351 / r5439347;
double r5439353 = a;
double r5439354 = r5439353 * r5439346;
double r5439355 = r5439354 / r5439347;
double r5439356 = r5439352 - r5439355;
double r5439357 = r5439356 / r5439347;
double r5439358 = r5439344 / r5439347;
double r5439359 = r5439350 ? r5439357 : r5439358;
double r5439360 = r5439343 ? r5439348 : r5439359;
return r5439360;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
Results
| Original | 25.9 |
|---|---|
| Target | 0.4 |
| Herbie | 12.7 |
if c < -5.589725284818602e+116Initial program 41.3
Simplified41.3
rmApplied add-sqr-sqrt41.3
Applied associate-/r*41.3
rmApplied clear-num41.5
Simplified28.7
rmApplied associate-/r*28.1
Simplified28.1
Taylor expanded around -inf 15.8
Simplified15.8
if -5.589725284818602e+116 < c < 4.7901533884695995e+114Initial program 18.6
Simplified18.6
rmApplied add-sqr-sqrt18.6
Applied associate-/r*18.5
rmApplied clear-num18.7
Simplified11.8
rmApplied associate-/r*11.4
Simplified11.3
rmApplied div-sub11.3
if 4.7901533884695995e+114 < c Initial program 40.4
Simplified40.4
rmApplied add-sqr-sqrt40.4
Applied associate-/r*40.4
rmApplied clear-num40.4
Simplified27.7
rmApplied associate-/r*27.2
Simplified27.1
Taylor expanded around inf 15.4
Final simplification12.7
herbie shell --seed 2019200 +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))))