\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;d \le -9.494881135626707 \cdot 10^{+123}:\\
\;\;\;\;\frac{-b}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{elif}\;d \le 1.66807717135982 \cdot 10^{+77}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\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 r4881401 = a;
double r4881402 = c;
double r4881403 = r4881401 * r4881402;
double r4881404 = b;
double r4881405 = d;
double r4881406 = r4881404 * r4881405;
double r4881407 = r4881403 + r4881406;
double r4881408 = r4881402 * r4881402;
double r4881409 = r4881405 * r4881405;
double r4881410 = r4881408 + r4881409;
double r4881411 = r4881407 / r4881410;
return r4881411;
}
double f(double a, double b, double c, double d) {
double r4881412 = d;
double r4881413 = -9.494881135626707e+123;
bool r4881414 = r4881412 <= r4881413;
double r4881415 = b;
double r4881416 = -r4881415;
double r4881417 = c;
double r4881418 = hypot(r4881412, r4881417);
double r4881419 = r4881416 / r4881418;
double r4881420 = 1.66807717135982e+77;
bool r4881421 = r4881412 <= r4881420;
double r4881422 = a;
double r4881423 = r4881417 * r4881422;
double r4881424 = fma(r4881412, r4881415, r4881423);
double r4881425 = r4881424 / r4881418;
double r4881426 = r4881425 / r4881418;
double r4881427 = r4881415 / r4881418;
double r4881428 = r4881421 ? r4881426 : r4881427;
double r4881429 = r4881414 ? r4881419 : r4881428;
return r4881429;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.8 |
|---|---|
| Target | 0.5 |
| Herbie | 13.5 |
if d < -9.494881135626707e+123Initial program 42.8
Simplified42.8
rmApplied add-sqr-sqrt42.8
Applied associate-/r*42.8
rmApplied clear-num42.9
Simplified30.4
rmApplied associate-/r*29.8
Simplified29.8
Taylor expanded around -inf 15.4
Simplified15.4
if -9.494881135626707e+123 < d < 1.66807717135982e+77Initial program 19.0
Simplified19.0
rmApplied add-sqr-sqrt19.0
Applied associate-/r*18.9
rmApplied clear-num19.2
Simplified12.3
rmApplied associate-/r*11.9
Simplified11.8
if 1.66807717135982e+77 < d Initial program 38.9
Simplified38.9
rmApplied add-sqr-sqrt38.9
Applied associate-/r*38.9
rmApplied clear-num39.0
Simplified26.8
rmApplied associate-/r*26.3
Simplified26.3
Taylor expanded around inf 17.4
Final simplification13.5
herbie shell --seed 2019165 +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))))