7 #include "cln/integer.h"
17 cl_signean compare (const cl_I& x, const cl_I& y)
20 // x und y haben verschiedenes Vorzeichen ->
23 // x und y haben gleiches Vorzeichen ->
25 // y Fixnum -> direkt vergleichen.
34 // falls beide gleich lang -> wortweise vergleichen
35 // x kürzer als y -> bei x,y > 0 : x < y, bei x,y < 0 : x > y
36 // y kürzer als x -> bei x,y > 0 : x > y, bei x,y > 0 : x < y
43 { // This assumes cl_value_shift + cl_value_len == cl_pointer_size.
44 if ((cl_sint)x.word == (cl_sint)y.word) return signean_null;
45 else if ((cl_sint)x.word > (cl_sint)y.word) return signean_plus;
46 else return signean_minus;
50 if ((sintD)mspref(BN_MSDptr(y),0) >= 0)
51 // x Fixnum, y Bignum >0
52 return signean_minus; // x<y
54 // x Fixnum, y Bignum <0
55 return signean_plus; // x>y
60 if ((sintD)mspref(BN_MSDptr(x),0) >= 0)
61 // x Bignum >0, y Fixnum
62 return signean_plus; // x>y
64 // x Bignum <0, y Fixnum
65 return signean_minus; // x<y
68 if ((sintD)mspref(BN_MSDptr(x),0) >= 0)
69 // x Bignum >0, y Bignum
70 if ((sintD)mspref(BN_MSDptr(y),0) >= 0)
72 if (x.pointer == y.pointer)
73 return signean_null; // gleiche Pointer -> selbe Zahl
75 { xlen = TheBignum(x)->length;
76 ylen = TheBignum(y)->length;
79 // gleiche Länge -> digitweise vergleichen
80 return compare_loop_msp(BN_MSDptr(x),BN_MSDptr(y),xlen);
82 return (xlen > ylen ? signean_plus : signean_minus);
85 // x Bignum >0, y Bignum <0
86 return signean_plus; // x>y
88 // x Bignum <0, y Bignum
89 if ((sintD)mspref(BN_MSDptr(y),0) >= 0)
90 // x Bignum <0, y Bignum >0
91 return signean_minus; // x<y
94 if (x.pointer == y.pointer)
95 return signean_null; // gleiche Pointer -> selbe Zahl
97 { xlen = TheBignum(x)->length;
98 ylen = TheBignum(y)->length;
100 // gleiche Länge -> wortweise vergleichen
101 goto samelength; // wie oben
103 return (xlen > ylen ? signean_minus : signean_plus);