#include "cln/number.h"
#include "cln/integer.h"
-#include "cl_macros.h"
+#include "base/cl_macros.h"
#include "cln/malloc.h"
-#include "cln/abort.h"
-#include "cl_offsetof.h"
-#include "cl_DS.h"
+#include "cln/exception.h"
+#include "base/cl_offsetof.h"
+#include "base/digitseq/cl_DS.h"
namespace cln {
// 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);
}
#if (intDsize<=32)
-// Holt die nächsten pFN_maxlength Digits in ein uintV.
+// Holt die nächsten pFN_maxlength Digits in ein uintV.
inline uintV pFN_maxlength_digits_at (const uintD* ptr)
{
#if (pFN_maxlength==1)
#endif
}
-// Schreibt ein uintV in die nächsten pFN_maxlength Digits.
+// Schreibt ein uintV in die nächsten pFN_maxlength Digits.
inline void set_pFN_maxlength_digits_at (uintD* ptr, uintV wert)
{
#if (pFN_maxlength==1)
#elif (intDsize==64)
-// Holt die nächsten pFN_maxlength Digits in ein uint64.
+// Holt die nächsten pFN_maxlength Digits in ein uint64.
inline uint64 pFN_maxlength_digits_at (const uintD* ptr)
{
return (uint64)lspref(ptr,0);
// Normalized Unsigned Digit Sequence to Integer
// NUDS_to_I(MSDptr,len)
// Normalized UDS MSDptr/len/.. in Integer >=0 umwandeln.
-// Unterhalb von MSDptr muß 1 Digit Platz sein.
+// Unterhalb von MSDptr muß 1 Digit Platz sein.
extern const cl_I NUDS_to_I (uintD* MSDptr, uintC len);
// Unsigned Digit Sequence to Integer
// UDS_to_I(MSDptr,len)
// UDS MSDptr/len/.. in Integer >=0 umwandeln.
-// Unterhalb von MSDptr muß 1 Digit Platz sein.
+// Unterhalb von MSDptr muß 1 Digit Platz sein.
extern const cl_I UDS_to_I (uintD* MSDptr, uintC len);
// Digit Sequence to Integer
#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)
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)
#endif
// wird nur bei FN_maxlength >= 2 gebraucht, d.h. intDsize < cl_value_len
-#define FN_MSD1_mask (~((cl_uint)(bitc(intDsize-1)-1) << cl_value_shift))
+#define FN_MSD1_mask ((~(cl_uint)(bitc(intDsize-1)-1)) << cl_value_shift)
// wird nur bei FN_maxlength >= 3 gebraucht, d.h. 2*intDsize < cl_value_len
-#define FN_MSD2_mask (~((cl_uint)(bitc(2*intDsize-1)-1) << cl_value_shift))
+#define FN_MSD2_mask ((~(cl_uint)(bitc(2*intDsize-1)-1)) << cl_value_shift)
// wird nur bei FN_maxlength >= 4 gebraucht, d.h. 3*intDsize < cl_value_len
-#define FN_MSD3_mask (~((cl_uint)(bitc(3*intDsize-1)-1) << cl_value_shift))
+#define FN_MSD3_mask ((~(cl_uint)(bitc(3*intDsize-1)-1)) << cl_value_shift)
// Store a Fixnum at destLSDptr, <= FN_maxlength digits below destLSDptr needed.
#define FN_to_NDS(destLSDptr, word, MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, check_for_0,zero_statement) \
unused (LSDptr_zuweisung (destLSDptr)); \
}
-// Bignum to Normalized Digit sequence, Kopieren unnötig
+// Bignum to Normalized Digit sequence, Kopieren unnötig
// BN_to_NDS_nocopy(obj, MSDptr=,len=,LSDptr=);
// > obj: ein Bignum
// < MSDptr/len/LSDptr: Normalized Digit sequence
copy_loop_msp(BN_MSDptr(obj_from_BN_to_NDS),MSDptr_from_BN_to_NDS,len_from_BN_to_NDS); \
}
-// Integer to Normalized Digit sequence, Kopieren unnötig.
+// Integer to Normalized Digit sequence, Kopieren unnötig.
// I_to_NDS_nocopy(obj, MSDptr=,len=,LSDptr=,check_for_0,zero_statement);
// > obj: ein Integer
-// > check_for_0: ob obj möglicherweise =0 sein kann
-// > zero_statement: wird bei obj=0 ausgeführt
+// > check_for_0: ob obj möglicherweise =0 sein kann
+// > zero_statement: wird bei obj=0 ausgeführt
// < MSDptr/len/LSDptr: Normalized Digit sequence
#define I_to_NDS_nocopy(obj, MSDptr_zuweisung,len_zuweisung,LSDptr_zuweisung, check_for_0,zero_statement) \
var uintD CONCAT(FN_store_,__LINE__) [FN_maxlength]; \
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); } \
}
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); } \
}
// < 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
- // Teilfunktion für die Durchführung des Euklid-Algorithmus auf
- // den führenden Ziffern a' und b':
+ // Teilfunktion für die Durchführung des Euklid-Algorithmus auf
+ // den führenden Ziffern a' und b':
// partial_gcd(a',b',&erg); mit a'>b'
// liefert in erg: x1,y1,x2,y2 mit den in cl_I_gcd.cc angegebenen Invarianten.
typedef struct { uintD x1,y1,x2,y2; } partial_gcd_result;
// > 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
// Wandelt eine Ziffernfolge in ein Integer >=0 um.
// digits_to_I(MSBptr,len,base)
// > base: Stellenwertsystem-Basis, >=2, <=36
-// > MSBptr/len/..: Ziffernfolge, bestehend aus Punkten (werden überlesen)
+// > MSBptr/len/..: Ziffernfolge, bestehend aus Punkten (werden überlesen)
// und Ziffern/Buchstaben mit Wert < base.
// < ergebnis: der dargestellte Integer >=0
extern const cl_I digits_to_I (const char * MSBptr, uintC len, uintD base);
// Hilfsfunktion zur Ausgabe von Integers
-// cl_digits_need(len,base) liefert eine obere Abschätzung für die Anzahl der
+// cl_digits_need(len,base) liefert eine obere Abschätzung für die Anzahl der
// Ziffern im Stellenwertsystem der Basis base, die x >= 0 braucht.
extern uintC cl_digits_need (const cl_I& x, uintL base);
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;
}
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