]> www.ginac.de Git - cln.git/blob - src/integer/bitwise/cl_I_logbitp_I.cc
2c40a1d3200f33d9d580346e6b4924e1e9c8ef3d
[cln.git] / src / integer / bitwise / cl_I_logbitp_I.cc
1 // logbitp().
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 "cln/io.h"
15 #include "cln/integer_io.h"
16 #include "cln/abort.h"
17
18 namespace cln {
19
20 cl_boolean logbitp (const cl_I& x, const cl_I& y)
21 {
22     // Methode:
23     // Falls x<0, Error.
24     // Falls x>=0: Falls x>=intDsize*Länge(y), teste Vorzeichen von y.
25     //             Sonst x=intDsize*k+i, Teste Bit i vom Worte Nr. k+1 (von oben herab).
26       if (!minusp(x)) // x>=0 ?
27         { if (fixnump(x))
28             { var uintV x_ = FN_to_V(x);
29               var uintC ylen;
30               var const uintD* yLSDptr;
31               I_to_NDS_nocopy(y, ,ylen=,yLSDptr=,cl_true, { return cl_false; } ); // DS zu y
32               if (x_ < intDsize*(uintL)ylen)
33                 // x ist ein Fixnum >=0, < intDsize*ylen
34                 { if (lspref(yLSDptr,floor(x_,intDsize)) & bit(x_%intDsize))
35                     return cl_true;
36                     else
37                     return cl_false;
38             }   }
39           // Vorzeichen von y testen
40           if (minusp(y))
41             return cl_true;
42             else
43             return cl_false;
44         }
45         else
46         // x<0
47         { fprint(std::cerr, "logbitp: Index is negative: ");
48           fprint(std::cerr, x);
49           fprint(std::cerr, "\n");
50           cl_abort();
51         }
52 }
53
54 }  // namespace cln