\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.942116530425900725431758127434894134157 \cdot 10^{195}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 4.355931456769410941675116004628825267272 \cdot 10^{151}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(a, c, b \cdot d\right)}{\mathsf{hypot}\left(c, d\right)}}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\end{array}double f(double a, double b, double c, double d) {
double r114277 = a;
double r114278 = c;
double r114279 = r114277 * r114278;
double r114280 = b;
double r114281 = d;
double r114282 = r114280 * r114281;
double r114283 = r114279 + r114282;
double r114284 = r114278 * r114278;
double r114285 = r114281 * r114281;
double r114286 = r114284 + r114285;
double r114287 = r114283 / r114286;
return r114287;
}
double f(double a, double b, double c, double d) {
double r114288 = c;
double r114289 = -3.9421165304259007e+195;
bool r114290 = r114288 <= r114289;
double r114291 = -1.0;
double r114292 = a;
double r114293 = r114291 * r114292;
double r114294 = d;
double r114295 = hypot(r114288, r114294);
double r114296 = 1.0;
double r114297 = r114295 * r114296;
double r114298 = r114293 / r114297;
double r114299 = 4.355931456769411e+151;
bool r114300 = r114288 <= r114299;
double r114301 = b;
double r114302 = r114301 * r114294;
double r114303 = fma(r114292, r114288, r114302);
double r114304 = r114303 / r114295;
double r114305 = r114304 / r114297;
double r114306 = r114292 / r114297;
double r114307 = r114300 ? r114305 : r114306;
double r114308 = r114290 ? r114298 : r114307;
return r114308;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.3 |
|---|---|
| Target | 0.5 |
| Herbie | 13.4 |
if c < -3.9421165304259007e+195Initial program 43.4
rmApplied add-sqr-sqrt43.4
Applied *-un-lft-identity43.4
Applied times-frac43.4
Simplified43.4
Simplified31.4
rmApplied associate-*r/31.4
Simplified31.4
Taylor expanded around -inf 12.9
if -3.9421165304259007e+195 < c < 4.355931456769411e+151Initial program 20.9
rmApplied add-sqr-sqrt21.0
Applied *-un-lft-identity21.0
Applied times-frac21.0
Simplified21.0
Simplified13.5
rmApplied associate-*r/13.4
Simplified13.3
if 4.355931456769411e+151 < c Initial program 44.3
rmApplied add-sqr-sqrt44.3
Applied *-un-lft-identity44.3
Applied times-frac44.3
Simplified44.3
Simplified28.6
rmApplied associate-*r/28.6
Simplified28.6
Taylor expanded around inf 13.9
Final simplification13.4
herbie shell --seed 2019354 +o rules:numerics
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
: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))))