\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -7.4027860136639313 \cdot 10^{164}:\\
\;\;\;\;\frac{-1 \cdot a}{\mathsf{hypot}\left(c, d\right) \cdot 1}\\
\mathbf{elif}\;c \le 9.2828111171168996 \cdot 10^{132}:\\
\;\;\;\;\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 r105314 = a;
double r105315 = c;
double r105316 = r105314 * r105315;
double r105317 = b;
double r105318 = d;
double r105319 = r105317 * r105318;
double r105320 = r105316 + r105319;
double r105321 = r105315 * r105315;
double r105322 = r105318 * r105318;
double r105323 = r105321 + r105322;
double r105324 = r105320 / r105323;
return r105324;
}
double f(double a, double b, double c, double d) {
double r105325 = c;
double r105326 = -7.402786013663931e+164;
bool r105327 = r105325 <= r105326;
double r105328 = -1.0;
double r105329 = a;
double r105330 = r105328 * r105329;
double r105331 = d;
double r105332 = hypot(r105325, r105331);
double r105333 = 1.0;
double r105334 = r105332 * r105333;
double r105335 = r105330 / r105334;
double r105336 = 9.2828111171169e+132;
bool r105337 = r105325 <= r105336;
double r105338 = b;
double r105339 = r105338 * r105331;
double r105340 = fma(r105329, r105325, r105339);
double r105341 = r105340 / r105332;
double r105342 = r105341 / r105334;
double r105343 = r105329 / r105334;
double r105344 = r105337 ? r105342 : r105343;
double r105345 = r105327 ? r105335 : r105344;
return r105345;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.9 |
|---|---|
| Target | 0.4 |
| Herbie | 12.9 |
if c < -7.402786013663931e+164Initial program 47.0
rmApplied add-sqr-sqrt47.0
Applied *-un-lft-identity47.0
Applied times-frac47.0
Simplified47.0
Simplified32.4
rmApplied associate-*r/32.4
Simplified32.3
Taylor expanded around -inf 13.2
if -7.402786013663931e+164 < c < 9.2828111171169e+132Initial program 20.4
rmApplied add-sqr-sqrt20.4
Applied *-un-lft-identity20.4
Applied times-frac20.4
Simplified20.4
Simplified12.7
rmApplied associate-*r/12.7
Simplified12.6
if 9.2828111171169e+132 < c Initial program 41.9
rmApplied add-sqr-sqrt41.9
Applied *-un-lft-identity41.9
Applied times-frac41.9
Simplified41.9
Simplified27.4
rmApplied associate-*r/27.4
Simplified27.4
Taylor expanded around inf 14.1
Final simplification12.9
herbie shell --seed 2020064 +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))))