X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;ds=sidebyside;f=src%2Fmodinteger%2Fcl_MI_std.h;h=04fd37bb0c84457d439ce68b5c7e3b7431ddd57d;hb=c84c6db5d56829d69083c819688a973867694a2a;hp=4cd56e07ed86be282d67fccda21264171c974853;hpb=dd9e0f894eec7e2a8cf85078330ddc0a6639090b;p=cln.git diff --git a/src/modinteger/cl_MI_std.h b/src/modinteger/cl_MI_std.h index 4cd56e0..04fd37b 100644 --- a/src/modinteger/cl_MI_std.h +++ b/src/modinteger/cl_MI_std.h @@ -1,6 +1,8 @@ // m > 1, standard representation, no tricks -static void std_fprint (cl_heap_modint_ring* R, cl_ostream stream, const _cl_MI &x) +namespace cln { + +static void std_fprint (cl_heap_modint_ring* R, std::ostream& stream, const _cl_MI &x) { fprint(stream,R->_retract(x)); fprint(stream," mod "); @@ -23,7 +25,7 @@ static const cl_I std_retract (cl_heap_modint_ring* R, const _cl_MI& x) return x.rep; } -static const _cl_MI std_random (cl_heap_modint_ring* R, cl_random_state& randomstate) +static const _cl_MI std_random (cl_heap_modint_ring* R, random_state& randomstate) { return _cl_MI(R, random_I(randomstate,R->modulus)); } @@ -169,11 +171,11 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const // k = 3 for nn <= 69.8 // ... k for nn <= k*(k+1)*2^(2k)/(2^(k+1)-k-2) var cl_I n = y; - var uintL nn = integer_length(n); + var uintC nn = integer_length(n); // n has nn bits. if (nn <= 8) { // k = 1, normal Left-Right Binary algorithm. - var uintL _n = FN_to_UL(n); + var uintL _n = FN_to_UV(n); var _cl_MI a = x; for (var int i = nn-2; i >= 0; i--) { a = R->_square(a); @@ -200,7 +202,7 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const else if (nn <= 1721160) k = 14; else if (nn <= 3933180) k = 15; else /* if (nn <= 8914120) */ k = 16; - var uintL nnk = ceiling(nn,k); // number of base-2^k digits in n + var uintC nnk = ceiling(nn,k); // number of base-2^k digits in n var uint16* n_digits = cl_alloc_array(uint16,nnk); // Split n into base-2^k digits. { @@ -210,7 +212,7 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const var const uintL k_mask = bit(k)-1; var uintD carry = 0; var unsigned int carrybits = 0; - for (var uintL i = 0; i < nnk; i++) { + for (var uintC i = 0; i < nnk; i++) { if (carrybits >= k) { n_digits[i] = carry & k_mask; carry = carry >> k; @@ -227,7 +229,7 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const // Compute maximum odd base-2^k digit. var uintL maxodd = 1; if (k <= 8) { - for (var uintL i = 0; i < nnk; i++) { + for (var uintC i = 0; i < nnk; i++) { var uintL d = n_digits[i]; if (d > 0) { d = odd_table[d]; @@ -235,7 +237,7 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const } } } else { - for (var uintL i = 0; i < nnk; i++) { + for (var uintC i = 0; i < nnk; i++) { var uintL d = n_digits[i]; if (d > 0) { var uintL d2; ord2_32(d,d2=); @@ -273,7 +275,7 @@ static const _cl_MI std_expt_pos (cl_heap_modint_ring* R, const _cl_MI& x, const for ( ; d2>0; d2--) a = R->_square(a); } - for (var sintL i = nnk-2; i >= 0; i--) { + for (var sintC i = nnk-2; i >= 0; i--) { // Compute a := a^(2^k) * x^n_digits[i]. var uintL d = n_digits[i]; var uintL d2; @@ -343,8 +345,26 @@ class cl_heap_modint_ring_std : public cl_heap_modint_ring { SUBCLASS_cl_heap_modint_ring() public: // Constructor. - cl_heap_modint_ring_std (const cl_I& m) - : cl_heap_modint_ring (m, &std_setops, &std_addops, &std_mulops) {} + cl_heap_modint_ring_std (const cl_I& m); // Virtual destructor. ~cl_heap_modint_ring_std () {} }; + +static void cl_heap_modint_ring_std_destructor (cl_heap* pointer) +{ + (*(cl_heap_modint_ring_std*)pointer).~cl_heap_modint_ring_std(); +} + +cl_class cl_class_modint_ring_std = { + cl_heap_modint_ring_std_destructor, + cl_class_flags_modint_ring +}; + +// Constructor. +inline cl_heap_modint_ring_std::cl_heap_modint_ring_std (const cl_I& m) + : cl_heap_modint_ring (m, &std_setops, &std_addops, &std_mulops) +{ + type = &cl_class_modint_ring_std; +} + +} // namespace cln