]> www.ginac.de Git - cln.git/blobdiff - src/integer/conv/cl_I_to_UL.cc
Avoid some "suggest explicit braces to avoid ambiguous ‘else’" warnings.
[cln.git] / src / integer / conv / cl_I_to_UL.cc
index c4fffac9b24a69d60d29a46558a346694e91e793..b5d57063a08a214fe7aea68ca657f4624fb23bb7 100644 (file)
@@ -1,7 +1,7 @@
 // cl_I_to_UL().
 
 // General includes.
-#include "cl_sysdep.h"
+#include "base/cl_sysdep.h"
 
 // Specification.
 #include "cln/integer.h"
 // Implementation.
 
 #include "cln/number.h"
-#include "cl_I.h"
-#include "cl_DS.h"
+#include "integer/cl_I.h"
+#include "base/digitseq/cl_DS.h"
 #include "cln/io.h"
 #include "cln/integer_io.h"
-#include "cln/abort.h"
+#include "cln/exception.h"
+#include <sstream>
 
 namespace cln {
 
@@ -22,9 +23,12 @@ uint32 cl_I_to_UL (const cl_I& obj)
 {
        if (fixnump(obj)) {
                // Fixnum
-               var sint32 wert = FN_to_L(obj);
+               var sintV wert = FN_to_V(obj);
                if (wert >= 0)
-                       return (uint32)wert;
+                       #if (intVsize>32)
+                       if (wert < bit(32))
+                       #endif
+                               return (uint32)wert;
                goto bad;
        } else { // Bignum
                var cl_heap_bignum* bn = TheBignum(obj);
@@ -32,7 +36,7 @@ uint32 cl_I_to_UL (const cl_I& obj)
                if ((sintD)mspref(arrayMSDptr(bn->data,len),0) < 0)
                        goto bad;
                #define IF_LENGTH(i)  \
-                 if (bn_minlength <= i) /* genau i Digits überhaupt möglich? */\
+                 if (bn_minlength <= i) /* genau i Digits überhaupt möglich? */\
                    if (len == i) /* genau i Digits? */                         \
                      /* 2^((i-1)*intDsize-1) <= obj < 2^(i*intDsize-1) */      \
                      if ( (i*intDsize-1 > 32)                                  \
@@ -54,10 +58,10 @@ uint32 cl_I_to_UL (const cl_I& obj)
                #undef IF_LENGTH
        }
        bad: // unpassendes Objekt
-       fprint(stderr, "Not a 32-bit integer: ");
-       fprint(stderr, obj);
-       fprint(stderr, "\n");
-       cl_abort();
+       std::ostringstream buf;
+       fprint(buf, "Not a 32-bit integer: ");
+       fprint(buf, obj);
+       throw runtime_exception(buf.str());
 }
 
 }  // namespace cln