\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le 7.643741764178763599768402058466858347704 \cdot 10^{138}:\\
\;\;\;\;\frac{\frac{\mathsf{fma}\left(b, d, a \cdot c\right)}{\mathsf{hypot}\left(d, c\right)}}{\mathsf{hypot}\left(d, c\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{hypot}\left(d, c\right)} \cdot a\\
\end{array}double f(double a, double b, double c, double d) {
double r5422610 = a;
double r5422611 = c;
double r5422612 = r5422610 * r5422611;
double r5422613 = b;
double r5422614 = d;
double r5422615 = r5422613 * r5422614;
double r5422616 = r5422612 + r5422615;
double r5422617 = r5422611 * r5422611;
double r5422618 = r5422614 * r5422614;
double r5422619 = r5422617 + r5422618;
double r5422620 = r5422616 / r5422619;
return r5422620;
}
double f(double a, double b, double c, double d) {
double r5422621 = c;
double r5422622 = 7.643741764178764e+138;
bool r5422623 = r5422621 <= r5422622;
double r5422624 = b;
double r5422625 = d;
double r5422626 = a;
double r5422627 = r5422626 * r5422621;
double r5422628 = fma(r5422624, r5422625, r5422627);
double r5422629 = hypot(r5422625, r5422621);
double r5422630 = r5422628 / r5422629;
double r5422631 = r5422630 / r5422629;
double r5422632 = 1.0;
double r5422633 = r5422632 / r5422629;
double r5422634 = r5422633 * r5422626;
double r5422635 = r5422623 ? r5422631 : r5422634;
return r5422635;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 26.0 |
|---|---|
| Target | 0.4 |
| Herbie | 14.8 |
if c < 7.643741764178764e+138Initial program 23.2
Simplified23.2
rmApplied clear-num23.4
rmApplied *-un-lft-identity23.4
Applied add-sqr-sqrt23.4
Applied times-frac23.4
Applied add-cube-cbrt23.4
Applied times-frac23.3
Simplified23.3
Simplified15.1
rmApplied associate-*r/15.1
Simplified15.0
if 7.643741764178764e+138 < c Initial program 42.3
Simplified42.3
rmApplied clear-num42.3
rmApplied *-un-lft-identity42.3
Applied add-sqr-sqrt42.3
Applied times-frac42.3
Applied add-cube-cbrt42.3
Applied times-frac42.3
Simplified42.3
Simplified28.9
Taylor expanded around 0 13.9
Final simplification14.8
herbie shell --seed 2019192 +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))))