]> www.ginac.de Git - cln.git/blob - src/float/dfloat/elem/cl_DF_compare.cc
Use paths relative the `src' directory in the #include directives.
[cln.git] / src / float / dfloat / elem / cl_DF_compare.cc
1 // compare().
2
3 // General includes.
4 #include "base/cl_sysdep.h"
5
6 // Specification.
7 #include "cln/dfloat.h"
8
9
10 // Implementation.
11
12 #include "float/dfloat/cl_DF.h"
13
14 namespace cln {
15
16 cl_signean compare (const cl_DF& x, const cl_DF& y)
17 {
18 // Methode:
19 // x und y haben verschiedenes Vorzeichen ->
20 //    x < 0 -> x < y
21 //    x >= 0 -> x > y
22 // x und y haben gleiches Vorzeichen ->
23 //    x >=0 -> vergleiche x und y (die rechten 53 Bits)
24 //    x <0 -> vergleiche y und x (die rechten 53 Bits)
25 #if (cl_word_size==64)
26       var dfloat x_ = TheDfloat(x)->dfloat_value;
27       var dfloat y_ = TheDfloat(y)->dfloat_value;
28       if ((sint64)y_ >= 0)
29         // y>=0
30         { if ((sint64)x_ >= 0)
31             // y>=0, x>=0
32             { if (x_ < y_) return signean_minus; // x<y
33               if (x_ > y_) return signean_plus; // x>y
34               return signean_null;
35             }
36             else
37             // y>=0, x<0
38             { return signean_minus; } // x<y
39         }
40         else
41         { if ((sint64)x_ >= 0)
42             // y<0, x>=0
43             { return signean_plus; } // x>y
44             else
45             // y<0, x<0
46             { if (x_ > y_) return signean_minus; // |x|>|y| -> x<y
47               if (x_ < y_) return signean_plus; // |x|<|y| -> x>y
48               return signean_null;
49             }
50         }
51 #else
52       var uint32 x_semhi = TheDfloat(x)->dfloat_value.semhi;
53       var uint32 y_semhi = TheDfloat(y)->dfloat_value.semhi;
54       var uint32 x_mlo = TheDfloat(x)->dfloat_value.mlo;
55       var uint32 y_mlo = TheDfloat(y)->dfloat_value.mlo;
56       if ((sint32)y_semhi >= 0)
57         // y>=0
58         { if ((sint32)x_semhi >= 0)
59             // y>=0, x>=0
60             { if (x_semhi < y_semhi) return signean_minus; // x<y
61               if (x_semhi > y_semhi) return signean_plus; // x>y
62               if (x_mlo < y_mlo) return signean_minus; // x<y
63               if (x_mlo > y_mlo) return signean_plus; // x>y
64               return signean_null;
65             }
66             else
67             // y>=0, x<0
68             { return signean_minus; } // x<y
69         }
70         else
71         { if ((sint32)x_semhi >= 0)
72             // y<0, x>=0
73             { return signean_plus; } // x>y
74             else
75             // y<0, x<0
76             { if (x_semhi > y_semhi) return signean_minus; // |x|>|y| -> x<y
77               if (x_semhi < y_semhi) return signean_plus; // |x|<|y| -> x>y
78               if (x_mlo > y_mlo) return signean_minus; // |x|>|y| -> x<y
79               if (x_mlo < y_mlo) return signean_plus; // |x|<|y| -> x>y
80               return signean_null;
81             }
82         }
83 #endif
84 }
85
86 }  // namespace cln