4 #include "base/cl_sysdep.h"
7 #include "cln/integer.h"
12 #include "cln/number.h"
13 #include "integer/cl_I.h"
14 #include "base/digitseq/cl_DS.h"
16 #include "cln/integer_io.h"
17 #include "cln/exception.h"
22 sint32 cl_I_to_L (const cl_I& obj)
26 var sintV wert = FN_to_V(obj);
28 if ((sintV)(sint32)wert != wert)
33 var cl_heap_bignum* bn = TheBignum(obj);
34 var uintC len = bn->length;
35 if ((sintD)mspref(arrayMSDptr(bn->data,len),0) >= 0) {
37 #define IF_LENGTH(i) \
38 if ((bn_minlength <= i) /* genau i Digits überhaupt möglich? */ \
39 && (len == i) /* genau i Digits? */ \
40 /* 2^((i-1)*intDsize-1) <= obj < 2^(i*intDsize-1) */ \
41 && ( (i*intDsize > 32) \
42 && ( ((i-1)*intDsize >= 32) \
43 || (mspref(arrayMSDptr(bn->data,len),0) >= (uintD)bitc(31-(i-1)*intDsize)) \
48 return get_uint1D_Dptr(arrayLSDptr(bn->data,1));
50 return get_uint2D_Dptr(arrayLSDptr(bn->data,2));
52 return get_uint3D_Dptr(arrayLSDptr(bn->data,3));
54 return get_uint4D_Dptr(arrayLSDptr(bn->data,4));
58 #define IF_LENGTH(i) \
59 if ((bn_minlength <= i) /* genau i Digits überhaupt möglich? */ \
60 && (len == i) /* genau i Digits? */ \
61 /* - 2^(i*intDsize-1) <= obj < - 2^((i-1)*intDsize-1) */ \
62 && ( (i*intDsize > 32) \
63 && ( ((i-1)*intDsize >= 32) \
64 || (mspref(arrayMSDptr(bn->data,len),0) < (uintD)(-bitc(31-(i-1)*intDsize))) \
69 return get_sint1D_Dptr(arrayLSDptr(bn->data,1));
71 return get_sint2D_Dptr(arrayLSDptr(bn->data,2));
73 return get_sint3D_Dptr(arrayLSDptr(bn->data,3));
75 return get_sint4D_Dptr(arrayLSDptr(bn->data,4));
79 bad: // unpassendes Objekt
80 std::ostringstream buf;
81 fprint(buf, "Not a 32-bit integer: ");
83 throw runtime_exception(buf.str());