]> www.ginac.de Git - cln.git/blob - src/integer/bitwise/cl_I_logior.cc
* All Files have been modified for inclusion of namespace cln;
[cln.git] / src / integer / bitwise / cl_I_logior.cc
1 // logior().
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_I_log.h"
15
16 namespace cln {
17
18 // Logische Operationen auf Integers:
19 // Methode: aus den Längen der beiden Argumente eine obere Schranke für
20 // die Länge des Ergebnisses berechnen (das Maximum der beiden Längen und
21 // FN_maxlength), so daß das MSD für unendlich viele Bits steht.
22 // Dann beide Argumente in gleichgroße Digit sequences umwandeln, Operation
23 // mit einer einfachen Schleife durchführen.
24
25 const cl_I logior (const cl_I& x, const cl_I& y)
26     { if (fixnump(x) && fixnump(y)) // Beides Fixnums -> ganz einfach:
27         { // bitweise als Fixnum zurück
28           return cl_I_from_word(x.word | y.word);
29         }
30         else
31         { CL_ALLOCA_STACK;
32           var uintC n; // Anzahl der Digits
33          {var uintC nx = I_to_DS_need(x);
34           var uintC ny = I_to_DS_need(y);
35           n = (nx>=ny ? nx : ny);
36          }
37          {var uintD* xptr; I_to_DS_n(x,n,xptr=); // Pointer in DS zu x
38           var uintD* yptr; I_to_DS_n(y,n,yptr=); // Pointer in DS zu y
39           var uintD* zptr = xptr; // Pointer aufs Ergebnis
40           or_loop_msp(xptr,yptr,n); // mit OR verknüpfen
41           return DS_to_I(zptr,n); // Ergebnis als Integer
42     }   }}
43
44 }  // namespace cln