7 #include "cl_rational.h"
13 #include "cl_integer.h"
15 cl_signean cl_compare (const cl_RA& r, const cl_RA& s)
18 // r,s Integer -> klar
21 // r Integer, s Ratio: r=a, s=b/c. Vergleiche a*c und b.
22 // r Ratio, s Integer: r=a/b, s=c. Vergleiche a und b*c.
23 // r,s Ratios: r=a/b, s=c/d. Vergleiche a*d und b*c.
24 // 1. Schritt: Test, ob beides Integers:
25 if (integerp(r) && integerp(s)) {
28 return cl_compare(r,s);
30 // r,s nicht beide Integers.
31 // 2. Schritt: Test, ob die Vorzeichen bereits das Ergebnis hergeben:
34 return signean_minus; // r<0, s>=0 -> r<s
37 return signean_plus; // r>=0, s<0 -> r>s
39 // r,s haben gleiches Vorzeichen.
40 // 3. Schritt: Fallunterscheidung nach Typen
44 // r Integer, s Ratio: r=a, s=b/c. Vergleiche a*c und b.
45 var const cl_I& a = r;
46 var const cl_I& b = numerator(s);
47 var const cl_I& c = denominator(s);
48 return cl_compare(a*c,b);
53 // r Ratio, s Integer: r=a/b, s=c. Vergleiche a und b*c.
54 var const cl_I& a = numerator(r);
55 var const cl_I& b = denominator(r);
56 var const cl_I& c = s;
57 return cl_compare(a,b*c);
62 // r,s Ratios: r=a/b, s=c/d. Vergleiche a*d und b*c.
63 var const cl_I& a = numerator(r);
64 var const cl_I& b = denominator(r);
65 var const cl_I& c = numerator(s);
66 var const cl_I& d = denominator(s);
67 return cl_compare(a*d,b*c);
70 // Beschleunigung durch Konversion zu Short-Floats diese zuerst vergleichen??