\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}\begin{array}{l}
\mathbf{if}\;c \le -3.712028832851069 \cdot 10^{+161}:\\
\;\;\;\;\frac{-a}{\sqrt{d^2 + c^2}^*}\\
\mathbf{elif}\;c \le 9.529062653614642 \cdot 10^{+142}:\\
\;\;\;\;\frac{\frac{1}{\frac{\sqrt{d^2 + c^2}^*}{(a \cdot c + \left(b \cdot d\right))_*}}}{\sqrt{d^2 + c^2}^*}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{\sqrt{d^2 + c^2}^*}\\
\end{array}double f(double a, double b, double c, double d) {
double r10748057 = a;
double r10748058 = c;
double r10748059 = r10748057 * r10748058;
double r10748060 = b;
double r10748061 = d;
double r10748062 = r10748060 * r10748061;
double r10748063 = r10748059 + r10748062;
double r10748064 = r10748058 * r10748058;
double r10748065 = r10748061 * r10748061;
double r10748066 = r10748064 + r10748065;
double r10748067 = r10748063 / r10748066;
return r10748067;
}
double f(double a, double b, double c, double d) {
double r10748068 = c;
double r10748069 = -3.712028832851069e+161;
bool r10748070 = r10748068 <= r10748069;
double r10748071 = a;
double r10748072 = -r10748071;
double r10748073 = d;
double r10748074 = hypot(r10748073, r10748068);
double r10748075 = r10748072 / r10748074;
double r10748076 = 9.529062653614642e+142;
bool r10748077 = r10748068 <= r10748076;
double r10748078 = 1.0;
double r10748079 = b;
double r10748080 = r10748079 * r10748073;
double r10748081 = fma(r10748071, r10748068, r10748080);
double r10748082 = r10748074 / r10748081;
double r10748083 = r10748078 / r10748082;
double r10748084 = r10748083 / r10748074;
double r10748085 = r10748071 / r10748074;
double r10748086 = r10748077 ? r10748084 : r10748085;
double r10748087 = r10748070 ? r10748075 : r10748086;
return r10748087;
}




Bits error versus a




Bits error versus b




Bits error versus c




Bits error versus d
| Original | 25.3 |
|---|---|
| Target | 0.5 |
| Herbie | 12.0 |
if c < -3.712028832851069e+161Initial program 44.3
Simplified44.3
rmApplied add-sqr-sqrt44.3
Applied associate-/r*44.3
rmApplied *-un-lft-identity44.3
Applied *-un-lft-identity44.3
Applied *-un-lft-identity44.3
Applied times-frac44.3
Applied times-frac44.3
Simplified44.3
Simplified30.0
Taylor expanded around -inf 12.2
Simplified12.2
if -3.712028832851069e+161 < c < 9.529062653614642e+142Initial program 18.8
Simplified18.8
rmApplied add-sqr-sqrt18.8
Applied associate-/r*18.7
rmApplied *-un-lft-identity18.7
Applied *-un-lft-identity18.7
Applied *-un-lft-identity18.7
Applied times-frac18.7
Applied times-frac18.7
Simplified18.7
Simplified11.7
rmApplied clear-num11.8
if 9.529062653614642e+142 < c Initial program 43.3
Simplified43.3
rmApplied add-sqr-sqrt43.3
Applied associate-/r*43.3
rmApplied *-un-lft-identity43.3
Applied *-un-lft-identity43.3
Applied *-un-lft-identity43.3
Applied times-frac43.3
Applied times-frac43.3
Simplified43.3
Simplified26.7
Taylor expanded around inf 12.8
Final simplification12.0
herbie shell --seed 2019119 +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))))