]> www.ginac.de Git - cln.git/blob - src/float/lfloat/elem/cl_LF_compare.cc
Update known-to-work-with compilers.
[cln.git] / src / float / lfloat / elem / cl_LF_compare.cc
1 // compare().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "cln/lfloat.h"
8
9
10 // Implementation.
11
12 #include "float/lfloat/cl_LF.h"
13 #include "base/digitseq/cl_DS.h"
14
15 #include "base/cl_inline.h"
16 #include "float/lfloat/elem/cl_LF_minusp.cc"
17
18 namespace cln {
19
20 cl_signean compare (const cl_LF& x, const cl_LF& y)
21 {
22 // Methode:
23 // x und y haben verschiedenes Vorzeichen ->
24 //    x < 0 -> x < y
25 //    x >= 0 -> x > y
26 // x und y haben gleiches Vorzeichen ->
27 //    x >=0 -> vergleiche x und y (die rechten 24 Bits)
28 //    x <0 -> vergleiche y und x (die rechten 24 Bits)
29       if (!minusp_inline(y))
30         // y>=0
31         { if (!minusp_inline(x))
32             // y>=0, x>=0
33             { // Vergleiche Exponenten und Mantissen:
34               { var uintE x_uexp = TheLfloat(x)->expo;
35                 var uintE y_uexp = TheLfloat(y)->expo;
36                 if (x_uexp < y_uexp) return signean_minus; // x<y
37                 if (x_uexp > y_uexp) return signean_plus; // x>y
38               }
39               { var uintC x_len = TheLfloat(x)->len;
40                 var uintC y_len = TheLfloat(y)->len;
41                 var uintC len = (x_len<y_len ? x_len : y_len); // min(x_len,y_len)
42                 // len Digits vergleichen:
43                 var cl_signean erg =
44                   compare_loop_msp(arrayMSDptr(TheLfloat(x)->data,x_len),arrayMSDptr(TheLfloat(y)->data,y_len),len);
45                 if (!(erg==0)) { return erg; } // verschieden -> fertig
46                 // gemeinsames Teilstück war gleich
47                 if (x_len == y_len) { return signean_null; } // gleiche Länge -> fertig
48                 if (x_len > y_len)
49                   // x länger als y
50                   { if (DS_test_loop(arrayMSDptr(TheLfloat(x)->data,x_len) mspop y_len,x_len-y_len,arrayLSDptr(TheLfloat(x)->data,x_len)))
51                       { return signean_plus; } // x>y
52                       else
53                       { return signean_null; }
54                   }
55                   else
56                   // y länger als x
57                   { if (DS_test_loop(arrayMSDptr(TheLfloat(y)->data,y_len) mspop x_len,y_len-x_len,arrayLSDptr(TheLfloat(y)->data,y_len)))
58                       { return signean_minus; } // x<y
59                       else
60                       { return signean_null; }
61                   }
62             } }
63             else
64             // y>=0, x<0
65             { return signean_minus; } // x<y
66         }
67         else
68         { if (!minusp_inline(x))
69             // y<0, x>=0
70             { return signean_plus; } // x>y
71             else
72             // y<0, x<0
73             { // Vergleiche Exponenten und Mantissen:
74               { var uintE x_uexp = TheLfloat(x)->expo;
75                 var uintE y_uexp = TheLfloat(y)->expo;
76                 if (x_uexp < y_uexp) return signean_plus; // |x|<|y| -> x>y
77                 if (x_uexp > y_uexp) return signean_minus; // |x|>|y| -> x<y
78               }
79               { var uintC x_len = TheLfloat(x)->len;
80                 var uintC y_len = TheLfloat(y)->len;
81                 var uintC len = (x_len<y_len ? x_len : y_len); // min(x_len,y_len)
82                 // len Digits vergleichen:
83                 var cl_signean erg =
84                   compare_loop_msp(arrayMSDptr(TheLfloat(y)->data,y_len),arrayMSDptr(TheLfloat(x)->data,x_len),len);
85                 if (!(erg==0)) { return erg; } // verschieden -> fertig
86                 // gemeinsames Teilstück war gleich
87                 if (x_len == y_len) { return signean_null; } // gleiche Länge -> fertig
88                 if (x_len > y_len)
89                   // x länger als y
90                   { if (DS_test_loop(arrayMSDptr(TheLfloat(x)->data,x_len) mspop y_len,x_len-y_len,arrayLSDptr(TheLfloat(x)->data,x_len)))
91                       { return signean_minus; } // |x|>|y| -> x<y
92                       else
93                       { return signean_null; }
94                   }
95                   else
96                   // y länger als x
97                   { if (DS_test_loop(arrayMSDptr(TheLfloat(y)->data,y_len) mspop x_len,y_len-x_len,arrayLSDptr(TheLfloat(y)->data,y_len)))
98                       { return signean_plus; } // |x|<|y| -> x>y
99                       else
100                       { return signean_null; }
101                   }
102             } }
103         }
104 }
105
106 }  // namespace cln