\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -2.2063458127550573 \cdot 10^{+100}:\\
\;\;\;\;\frac{-a}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{elif}\;c \le 4.054287420560557 \cdot 10^{+138}:\\
\;\;\;\;\frac{\frac{1}{\frac{1}{\frac{\mathsf{fma}\left(c, a, \left(d \cdot b\right)\right)}{\mathsf{hypot}\left(c, d\right)}}}}{\mathsf{hypot}\left(c, d\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right)}\\
\end{array}double f(double a, double b, double c, double d) {
double r33878397 = a;
double r33878398 = c;
double r33878399 = r33878397 * r33878398;
double r33878400 = b;
double r33878401 = d;
double r33878402 = r33878400 * r33878401;
double r33878403 = r33878399 + r33878402;
double r33878404 = r33878398 * r33878398;
double r33878405 = r33878401 * r33878401;
double r33878406 = r33878404 + r33878405;
double r33878407 = r33878403 / r33878406;
return r33878407;
}
double f(double a, double b, double c, double d) {
double r33878408 = c;
double r33878409 = -2.2063458127550573e+100;
bool r33878410 = r33878408 <= r33878409;
double r33878411 = a;
double r33878412 = -r33878411;
double r33878413 = d;
double r33878414 = hypot(r33878408, r33878413);
double r33878415 = r33878412 / r33878414;
double r33878416 = 4.054287420560557e+138;
bool r33878417 = r33878408 <= r33878416;
double r33878418 = 1.0;
double r33878419 = b;
double r33878420 = r33878413 * r33878419;
double r33878421 = fma(r33878408, r33878411, r33878420);
double r33878422 = r33878421 / r33878414;
double r33878423 = r33878418 / r33878422;
double r33878424 = r33878418 / r33878423;
double r33878425 = r33878424 / r33878414;
double r33878426 = r33878411 / r33878414;
double r33878427 = r33878417 ? r33878425 : r33878426;
double r33878428 = r33878410 ? r33878415 : r33878427;
return r33878428;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.1 |
|---|---|
| Target | 0.5 |
| Herbie | 13.1 |
if c < -2.2063458127550573e+100Initial program 38.4
rmApplied add-sqr-sqrt38.4
Applied associate-/r*38.4
rmApplied hypot-def38.4
Taylor expanded around -inf 16.7
Simplified16.7
if -2.2063458127550573e+100 < c < 4.054287420560557e+138Initial program 18.6
rmApplied add-sqr-sqrt18.6
Applied associate-/r*18.5
rmApplied hypot-def18.5
rmApplied clear-num18.6
Simplified11.8
rmApplied clear-num11.8
if 4.054287420560557e+138 < c Initial program 45.0
rmApplied add-sqr-sqrt45.0
Applied associate-/r*45.0
rmApplied hypot-def45.0
Taylor expanded around inf 14.5
Final simplification13.1
herbie shell --seed 2019128 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
:herbie-target
(if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d)))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))