]> www.ginac.de Git - cln.git/blobdiff - src/integer/cl_I.h
* */*: Remove cl_boolean, cl_true, and cl_false in favor of built-in
[cln.git] / src / integer / cl_I.h
index 52c137d0ecc1d0ca92694f2b354097eed9c85c74..5afeb4183b7c51101c97657718a3d686e62c4768 100644 (file)
@@ -7,7 +7,7 @@
 #include "cln/integer.h"
 #include "cl_macros.h"
 #include "cln/malloc.h"
-#include "cln/abort.h"
+#include "cln/exception.h"
 #include "cl_offsetof.h"
 #include "cl_DS.h"
 
@@ -77,35 +77,35 @@ inline cl_I::cl_I (cl_heap_bignum* ptr)
 // Integers in general.
 
 // Type tests.
-inline cl_boolean integerp (const cl_I& x)
-       { unused x; return cl_true; }
-inline cl_boolean fixnump (const cl_I& x)
-       { return (cl_boolean) !x.pointer_p(); }
-inline cl_boolean bignump (const cl_I& x)
+inline bool integerp (const cl_I& x)
+       { unused x; return true; }
+inline bool fixnump (const cl_I& x)
+       { return !x.pointer_p(); }
+inline bool bignump (const cl_I& x)
        { return x.pointer_p(); }
 
 // Sign test:
 
 // (MINUSP x) == (< x 0)
-inline cl_boolean minusp (const cl_I& x)
+inline bool minusp (const cl_I& x)
 {
        if (fixnump(x))
                // This assumes cl_value_shift + cl_value_len == cl_pointer_size.
-               return (cl_boolean)((cl_sint) x.word < 0);
+               return (cl_sint) x.word < 0;
        else
-               return (cl_boolean)((sintD)mspref(arrayMSDptr(TheBignum(x)->data,TheBignum(x)->length),0) < 0);
+               return (sintD)mspref(arrayMSDptr(TheBignum(x)->data,TheBignum(x)->length),0) < 0;
 }
 
 // (ZEROP x) == (= x 0)
-inline cl_boolean zerop (const cl_I& x)
+inline bool zerop (const cl_I& x)
 {
-       return (cl_boolean)(x.word == cl_combine(cl_FN_tag,0));
+       return x.word == cl_combine(cl_FN_tag,0);
 }
 
 // (EQ x y) == (= x y), assuming y a fixnum
-inline cl_boolean eq (const cl_I& x, sint32 y)
+inline bool eq (const cl_I& x, sint32 y)
 {
-       return (cl_boolean)(x.word == cl_combine(cl_FN_tag,y));
+       return x.word == cl_combine(cl_FN_tag,y);
 }
 
 
@@ -234,6 +234,11 @@ inline sint64 FN_to_Q (const cl_I& x)
        return cl_I(cl_I_constructor_from_UQ(wert));
   }
 
+  extern cl_private_thing cl_I_constructor_from_Q2 (sint64 wert_hi, uint64 wert_lo );
+  inline const cl_I Q2_to_I( sint64 wert_hi, uint64 wert_lo)
+  {
+       return cl_I(cl_I_constructor_from_Q2(wert_hi, wert_lo));
+  }
 #endif
 
 // Wandelt Doppel-Longword in Integer um.
@@ -290,6 +295,26 @@ inline sint64 FN_to_Q (const cl_I& x)
   #define UV_to_I(wert)  UQ_to_I(wert)
 #endif
 
+// Wandelt sintE in Integer um.
+// E_to_I(wert)
+// > wert: Wert des Integers, ein sintE.
+// < ergebnis: Integer mit diesem Wert.
+#if (intEsize<=32)
+  #define E_to_I(wert)  L_to_I(wert)
+#else
+  #define E_to_I(wert)  Q_to_I(wert)
+#endif
+
+// Wandelt uintE in Integer >=0 um.
+// UE_to_I(wert)
+// > wert: Wert des Integers, ein uintE.
+// < ergebnis: Integer mit diesem Wert.
+#if (intEsize<=32)
+  #define UE_to_I(wert)  UL_to_I(wert)
+#else
+  #define UE_to_I(wert)  UQ_to_I(wert)
+#endif
+
 // Wandelt uintD in Integer >=0 um.
 // UD_to_I(wert)
 // > wert: Wert des Integers, ein uintD.
@@ -313,6 +338,14 @@ inline const cl_I minus (uintL x, uintL y)
 #endif
 }
 
+#ifdef intQsize
+
+inline const cl_I minus (uintQ x, uintQ y)
+{
+       return Q2_to_I( (x<y ? -1 : 0), x-y );
+}
+
+#endif
 
 // Umwandlungsroutinen Digit sequence <--> Longword:
 
@@ -441,9 +474,9 @@ inline sintD FN_MSD (cl_uint word)
 
 #if (FN_maxlength==1)
   #define FN_LSD0(word)  FN_MSD(word)
-  #define FN_LSD1(word)  (cl_abort(), (uintD)0)  // never used
-  #define FN_LSD2(word)  (cl_abort(), (uintD)0)  // never used
-  #define FN_LSD3(word)  (cl_abort(), (uintD)0)  // never used
+  #define FN_LSD1(word)  (throw runtime_exception(), (uintD)0)  // never used
+  #define FN_LSD2(word)  (throw runtime_exception(), (uintD)0)  // never used
+  #define FN_LSD3(word)  (throw runtime_exception(), (uintD)0)  // never used
 #endif
 #if (FN_maxlength==2)
   inline uintD FN_LSD0 (cl_uint word)
@@ -451,8 +484,8 @@ inline sintD FN_MSD (cl_uint word)
        return (uintD)(word >> cl_value_shift);
   }
   #define FN_LSD1(word)  FN_MSD(word)
-  #define FN_LSD2(word)  (cl_abort(), (uintD)0)  // never used
-  #define FN_LSD3(word)  (cl_abort(), (uintD)0)  // never used
+  #define FN_LSD2(word)  (throw runtime_exception(), (uintD)0)  // never used
+  #define FN_LSD3(word)  (throw runtime_exception(), (uintD)0)  // never used
 #endif
 #if (FN_maxlength==4)
   inline uintD FN_LSD0 (cl_uint word)
@@ -593,7 +626,7 @@ inline sintD FN_MSD (cl_uint word)
     var uintD CONCAT(FN_store_,__LINE__) [FN_maxlength];               \
     { var const cl_I& obj_from_I_to_NDS = (obj);                       \
       if (fixnump(obj_from_I_to_NDS))                                  \
-        { FN_to_NDS(arrayLSDptr(CONCAT(FN_store_,__LINE__),FN_maxlength), cl_FN_word(obj_from_I_to_NDS), MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, cl_true,); } \
+        { FN_to_NDS(arrayLSDptr(CONCAT(FN_store_,__LINE__),FN_maxlength), cl_FN_word(obj_from_I_to_NDS), MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, true,); } \
         else                                                              \
         { BN_to_NDS(obj_from_I_to_NDS,MSDptr_zuweisung,len_zuweisung, LSDptr_zuweisung); } \
     }
@@ -608,7 +641,7 @@ inline sintD FN_MSD (cl_uint word)
     var uintD CONCAT(FN_store_,__LINE__) [1+FN_maxlength];             \
     { var const cl_I& obj_from_I_to_NDS = (obj);                       \
       if (fixnump(obj_from_I_to_NDS))                                  \
-        { FN_to_NDS(arrayLSDptr(CONCAT(FN_store_,__LINE__),1+FN_maxlength), cl_FN_word(obj_from_I_to_NDS), MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, cl_true,); } \
+        { FN_to_NDS(arrayLSDptr(CONCAT(FN_store_,__LINE__),1+FN_maxlength), cl_FN_word(obj_from_I_to_NDS), MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, true,); } \
         else                                                              \
         { BN_to_NDS_1(obj_from_I_to_NDS,MSDptr_zuweisung,len_zuweisung, LSDptr_zuweisung); } \
     }
@@ -623,9 +656,6 @@ inline sintD FN_MSD (cl_uint word)
 // < q,r: Quotient q, Rest r
   extern const cl_I_div_t cl_divide (const cl_I& x, const cl_I& y);
 
-// Fehler, wenn Quotient keine ganze Zahl ist
-  nonreturning_function(extern, cl_error_exquo, (const cl_I& x, const cl_I& y));
-
 
 // ggT und kgV von Integers
 
@@ -650,8 +680,8 @@ inline sintD FN_MSD (cl_uint word)
 // > n: ein Integer >0
 // > Annahme: x > 1 und n < (integer-length x).
 // < w: Integer (expt x (/ n)) falls x eine n-te Potenz
-// < ergebnis: cl_true         ........................, cl_false sonst
-  extern cl_boolean cl_rootp_aux (cl_I x, uintL n, cl_I* w);
+// < ergebnis: true            ........................, false sonst
+  extern bool cl_rootp_aux (cl_I x, uintL n, cl_I* w);
 
 
 // Hilfsfunktion zur Eingabe von Integers
@@ -691,19 +721,19 @@ inline sintD FN_MSD (cl_uint word)
 class cl_FN : public cl_I {
 public:
 // Optimization of method pointer_p().
-       cl_boolean pointer_p() const
-               { return cl_false; }
+       bool pointer_p() const
+               { return false; }
 };
 
-inline cl_boolean fixnump (const cl_FN& x)
-       { unused x; return cl_true; }
-inline cl_boolean bignump (const cl_FN& x)
-       { unused x; return cl_false; }
+inline bool fixnump (const cl_FN& x)
+       { unused x; return true; }
+inline bool bignump (const cl_FN& x)
+       { unused x; return false; }
 
-inline cl_boolean minusp (const cl_FN& x)
+inline bool minusp (const cl_FN& x)
 {
        // This assumes cl_value_shift + cl_value_len == cl_pointer_size.
-       return (cl_boolean)((cl_sint) x.word < 0);
+       return (cl_sint) x.word < 0;
 }
 
 
@@ -713,21 +743,21 @@ inline cl_boolean minusp (const cl_FN& x)
 class cl_BN : public cl_I {
 public:
 // Optimization of method pointer_p().
-       cl_boolean pointer_p() const
-               { return cl_true; }
+       bool pointer_p() const
+               { return true; }
 };
 
-inline cl_boolean fixnump (const cl_BN& x)
-       { unused x; return cl_false; }
-inline cl_boolean bignump (const cl_BN& x)
-       { unused x; return cl_true; }
+inline bool fixnump (const cl_BN& x)
+       { unused x; return false; }
+inline bool bignump (const cl_BN& x)
+       { unused x; return true; }
 
-inline cl_boolean minusp (const cl_BN& x)
+inline bool minusp (const cl_BN& x)
 {
-       return (cl_boolean)((sintD)mspref(arrayMSDptr(TheBignum(x)->data,TheBignum(x)->length),0) < 0);
+       return (sintD)mspref(arrayMSDptr(TheBignum(x)->data,TheBignum(x)->length),0) < 0;
 }
-inline cl_boolean zerop (const cl_BN& x)
-       { unused x; return cl_false; }
+inline bool zerop (const cl_BN& x)
+       { unused x; return false; }
 
 }  // namespace cln