]> www.ginac.de Git - cln.git/blob - src/integer/elem/cl_I_mul.cc
* */*: Convert encoding from ISO 8859-1 to UTF-8.
[cln.git] / src / integer / elem / cl_I_mul.cc
1 // binary operator *
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cln/integer.h"
8
9
10 // Implementation.
11
12 #include "cl_I.h"
13 #include "cl_DS.h"
14 #include "cl_low.h"
15
16 namespace cln {
17
18 const cl_I operator* (const cl_I& x, const cl_I& y)
19 {
20   // Methode:
21   // x=0 oder y=0 -> Ergebnis 0
22   // x und y beide Fixnums -> direkt multiplizieren
23   // sonst: zu DS machen, multiplizieren.
24       if (zerop(x))
25         { return 0; }
26       if (zerop(y))
27         { return 0; }
28       if (fixnump(x) && fixnump(y))
29         { var sintV x_ = FN_to_V(x);
30           var sintV y_ = FN_to_V(y);
31           #if (cl_value_len > 32)
32           // nur falls x und y Integers mit höchstens 32 Bit sind:
33           if (((uintV)((sintV)sign_of(x_) ^ x_) < bit(31))
34               && ((uintV)((sintV)sign_of(y_) ^ y_) < bit(31)))
35           #endif
36             {
37               // Werte direkt multiplizieren:
38               var uint32 hi;
39               var uint32 lo;
40               mulu32((uint32)x_,(uint32)y_,hi=,lo=); // erst unsigned multiplizieren
41               if (x_ < 0) { hi -= (uint32)y_; } // dann Korrektur für Vorzeichen
42               if (y_ < 0) { hi -= (uint32)x_; } // (vgl. DS_DS_mul_DS)
43               return L2_to_I(hi,lo);
44             }
45         }
46       CL_ALLOCA_STACK;
47       var const uintD* xMSDptr;
48       var uintC xlen;
49       var const uintD* xLSDptr;
50       var const uintD* yMSDptr;
51       var uintC ylen;
52       var const uintD* yLSDptr;
53       var uintD* ergMSDptr;
54       var uintC erglen;
55       I_to_NDS_nocopy(x, xMSDptr = , xlen = , xLSDptr = , false,);
56       I_to_NDS_nocopy(y, yMSDptr = , ylen = , yLSDptr = , false,);
57       DS_DS_mul_DS(xMSDptr,xlen,xLSDptr,yMSDptr,ylen,yLSDptr, ergMSDptr=,erglen=,);
58       return DS_to_I(ergMSDptr,erglen);
59 }
60 // Bit complexity (x,y of length N): O(M(N)).
61
62 }  // namespace cln