X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;f=src%2Finteger%2Fcl_I.h;h=8c1c3d5e3f64f6872cebc365e35313c0b3107cc8;hb=740c032627dfc7ac87d90d6e75b5e87e78c9e716;hp=52c137d0ecc1d0ca92694f2b354097eed9c85c74;hpb=c84c6db5d56829d69083c819688a973867694a2a;p=cln.git diff --git a/src/integer/cl_I.h b/src/integer/cl_I.h index 52c137d..8c1c3d5 100644 --- a/src/integer/cl_I.h +++ b/src/integer/cl_I.h @@ -5,11 +5,11 @@ #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 { @@ -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,12 +338,20 @@ 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 Longword: #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) @@ -340,7 +373,7 @@ inline uintV pFN_maxlength_digits_at (const uintD* ptr) #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) @@ -392,7 +425,7 @@ inline void set_pFN_maxlength_digits_at (uintD* ptr, uintV wert) #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); @@ -411,13 +444,13 @@ inline uint64 pFN_maxlength_digits_at (const uintD* ptr) // 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 @@ -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) @@ -471,11 +504,11 @@ inline sintD FN_MSD (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) \ @@ -518,7 +551,7 @@ inline sintD FN_MSD (cl_uint word) 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 @@ -569,11 +602,11 @@ inline sintD FN_MSD (cl_uint word) 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]; \ @@ -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,14 +656,11 @@ 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 - // 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; @@ -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 @@ -659,7 +689,7 @@ inline sintD FN_MSD (cl_uint word) // 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); @@ -667,7 +697,7 @@ inline sintD FN_MSD (cl_uint word) // 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); @@ -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