|
numerix_doc 0.4
|
#include <modular_int.hpp>
Definition at line 507 of file modular_int.hpp.
| static void add_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 195 of file modular_int.hpp.
References modulus_add_int_naive< V >::add_mod_core().
{
add_mod_core (dest, s, m.p); }
| static void add_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 199 of file modular_int.hpp.
References modulus_add_int_naive< V >::add_mod_core().
{
add_mod_core (dest, s, m.p, carry); }
| static void add_mod | ( | C & | dest, |
| const C & | s1, | ||
| const C & | s2, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 203 of file modular_int.hpp.
References modulus_add_int_naive< V >::add_mod().
{
dest = s1;
add_mod (dest, s2, m); }
| static void add_mod | ( | C & | dest, |
| const C & | s1, | ||
| const C & | s2, | ||
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 208 of file modular_int.hpp.
References modulus_add_int_naive< V >::add_mod().
{
dest = s1;
add_mod (dest, s2, m, carry); }
| static void add_mod_core | ( | C & | dest, |
| const C & | s, | ||
| const C & | p | ||
| ) | [inline, static, inherited] |
Definition at line 187 of file modular_int.hpp.
{
add_mod_helper<C,is_signed_helper<C>::value>::op (dest, s, p); }
| static void add_mod_core | ( | C & | dest, |
| const C & | s, | ||
| const C & | p, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 191 of file modular_int.hpp.
{
add_mod_helper<C,is_signed_helper<C>::value>::op (dest, s, p, carry); }
| static void add_mod_with_overflow | ( | C & | dest, |
| const C & | s, | ||
| const C & | p | ||
| ) | [inline, static, inherited] |
Definition at line 140 of file modular_int.hpp.
{
dest += s;
if (dest < s) { dest -= p; return; }
if (dest >= p) dest -= p; }
| static void add_mod_with_overflow | ( | C & | dest, |
| const C & | s, | ||
| const C & | p, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 146 of file modular_int.hpp.
{
VERIFY (carry == 0 || carry == 1, "unexpected large carry");
dest += s + carry;
if (dest < s || dest >= p) { dest -= p; carry= 1; }
else carry= 0; }
| static void add_mod_without_overflow | ( | C & | dest, |
| const C & | s, | ||
| const C & | p, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 134 of file modular_int.hpp.
{
VERIFY (carry == 0 || carry == 1, "unexpected large carry");
dest += s + carry;
if (dest >= p) { dest -= p; carry= 1; } else carry= 0; }
| static void add_mod_without_overflow | ( | C & | dest, |
| const C & | s, | ||
| const C & | p | ||
| ) | [inline, static, inherited] |
Definition at line 129 of file modular_int.hpp.
{
dest += s;
if (dest >= p) dest -= p; }
| static void decode_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 501 of file modular_int.hpp.
{
(void) m;
dest = s; }
| static void div_mod | ( | C & | dest, |
| const C & | s1, | ||
| const C & | s2, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 481 of file modular_int.hpp.
References modulus_div_int_naive< V >::div_mod().
{
dest = s1;
div_mod (dest, s2, m); }
| static void div_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 475 of file modular_int.hpp.
References mmx::C, mmx::inv_mod(), and mmx::mul_mod().
{
C t = s;
V::inv_mod (t, m);
V::mul_mod (dest, t, m); }
| static void encode_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 489 of file modular_int.hpp.
References mmx::C, mmx::reduce_mod(), and mmx::sign().
{
typedef typename unsigned_of_helper<C>::type uC;
if (sign (s) < 0) {
uC tmp = - ((uC) s);
V::reduce_mod (tmp, m);
dest = (C) (((uC) m.p) - tmp);
}
else
dest = s;
V::reduce_mod (dest, m);
}
| static void inv_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 466 of file modular_int.hpp.
References modulus_inv_int_naive< V >::inv_mod().
{
dest = s;
inv_mod (dest, m); }
| static void inv_mod | ( | C & | a, |
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 459 of file modular_int.hpp.
References mmx::C, modulus_inv_int_naive< V >::inv_mod_signed(), and modulus_inv_int_naive< V >::inv_mod_unsigned().
{
if (V::template maximum_size_helper<C>::value >= 8*sizeof(C))
inv_mod_unsigned(a, m.p);
else
inv_mod_signed(a, m.p); }
| static void inv_mod_signed | ( | C & | a, |
| const C & | p | ||
| ) | [inline, static, inherited] |
Definition at line 402 of file modular_int.hpp.
{
typedef typename unsigned_of_helper<C>::type uC;
typedef typename signed_of_helper<C>::type sC;
sC coa0=0, coa1=1, r0=p, r1=a, q, t;
if ((p == 0) && (r1 != 0)) {
q = (((uC) r0) - ((uC) r1)) / ((uC) r1) + 1;
t = r0 - q * r1;
r0 = r1;
r1 = t;
t = coa1;
coa1 = coa0 - q * coa1;
coa0 = t;
}
while (r1 != 0) {
q = r0 / r1;
t = r0 - q * r1;
r0 = r1;
r1 = t;
t = coa1;
coa1 = coa0 - q * coa1;
coa0 = t;
}
if (r0 != 1)
ERROR ("inv_mod: argument is not invertible");
a = coa0 < 0 ? p+coa0 : coa0;
}
| static void inv_mod_unsigned | ( | C & | a, |
| const C & | p | ||
| ) | [inline, static, inherited] |
Definition at line 430 of file modular_int.hpp.
References mmx::C.
{
C coa0=0, coa1=1, r0=p, r1=a, q, t;
bool toggle = true;
if ((p == 0) && (r1 != 0)) {
q = (r0-r1) / r1 + 1;
t = r0 - q * r1;
r0 = r1;
r1 = t;
t = coa1;
coa1 = coa0 - q * coa1;
coa0 = t;
toggle = !toggle;
}
while (r1 != 0) {
q = r0 / r1;
t = r0 - q * r1;
r0 = r1;
r1 = t;
t = coa1;
coa1 = coa0 - q * coa1;
coa0 = t;
toggle = !toggle;
}
if (r0 != 1)
ERROR ("inv_mod: argument is not invertible");
a = (toggle && (coa0 != 0)) ? p+coa0 : coa0;
}
| static void mul_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 359 of file modular_int.hpp.
References mmx::D, modulus_mul_int_naive< V >::mul_mod(), and modulus_mul_int_naive< V >::mul_mod_helper< C, D >::op().
| static void mul_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 373 of file modular_int.hpp.
References mmx::D, modulus_mul_int_naive< V >::mul_mod(), and modulus_mul_int_naive< V >::mul_mod_helper< C, D >::op().
| static void mul_mod | ( | C & | dest, |
| const C & | s1, | ||
| const C & | s2, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 387 of file modular_int.hpp.
References modulus_mul_int_naive< V >::mul_mod().
{
dest = s1;
mul_mod (dest, s2, m); }
| static void mul_mod | ( | C & | dest, |
| const C & | s1, | ||
| const C & | s2, | ||
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 392 of file modular_int.hpp.
References modulus_mul_int_naive< V >::mul_mod().
{
dest = s1;
mul_mod (dest, s2, m, carry); }
| static void neg_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 123 of file modular_int.hpp.
{
VERIFY (carry == 0 || carry == 1, "unexpected large carry");
if (s != 0 || carry != 0) { dest= m.p - s - carry; carry= 1; }
else dest= 0; }
| static void neg_mod | ( | C & | dest, |
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 110 of file modular_int.hpp.
{
if (dest != 0) dest = m.p - dest; }
| static void neg_mod | ( | C & | dest, |
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 114 of file modular_int.hpp.
{
VERIFY (carry == 0 || carry == 1, "unexpected large carry");
if (dest != 0 || carry != 0) { dest= m.p - dest - carry; carry= 1; } }
| static void neg_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 119 of file modular_int.hpp.
{
if (s != 0) dest = m.p - s; else dest = s; }
| static bool normalize | ( | C & | p | ) | [inline, static, inherited] |
Definition at line 66 of file modular_int.hpp.
References mmx::abs().
{
typedef typename unsigned_of_helper<C>::type uC;
static const uC a = MMX_SAFE_LEFT_SHIFT_INT(uC, 1,
V::template maximum_size_helper<C>::value);
p = abs (p);
if ((uC) p == a || p == 0) { p = a; return true; }
return p <= V::template maximum_value_helper<C>::dyn_value ();
}
| static void reduce_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 96 of file modular_int.hpp.
References mmx::C, and modulus_reduction_int_naive< V >::reduce_mod_core().
{
dest = s;
reduce_mod_core (dest, (C) m.p); }
| static void reduce_mod | ( | C & | dest, |
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 88 of file modular_int.hpp.
References mmx::C, and modulus_reduction_int_naive< V >::reduce_mod_core().
{
reduce_mod_core (dest, (C) m.p); }
| static void reduce_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 101 of file modular_int.hpp.
References mmx::C, and modulus_reduction_int_naive< V >::reduce_mod_core().
{
dest = s;
reduce_mod_core (dest, (C) m.p, carry); }
| static void reduce_mod | ( | C & | dest, |
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 92 of file modular_int.hpp.
References mmx::C, and modulus_reduction_int_naive< V >::reduce_mod_core().
{
reduce_mod_core (dest, (C) m.p, carry); }
| static void reduce_mod_core | ( | C & | dest, |
| const C & | p | ||
| ) | [inline, static, inherited] |
Definition at line 79 of file modular_int.hpp.
{
if (p != 0) dest %= p; }
| static void reduce_mod_core | ( | C & | dest, |
| const C & | p, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 83 of file modular_int.hpp.
{
if (p != 0) { carry= dest / p; dest %= p; }
else carry = 0; }
| static void sub_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 225 of file modular_int.hpp.
References modulus_add_int_naive< V >::sub_mod_core().
{
sub_mod_core (dest, s, m.p); }
| static void sub_mod | ( | C & | dest, |
| const C & | s1, | ||
| const C & | s2, | ||
| const M & | m | ||
| ) | [inline, static, inherited] |
Definition at line 233 of file modular_int.hpp.
References modulus_add_int_naive< V >::sub_mod().
{
dest = s1;
sub_mod (dest, s2, m); }
| static void sub_mod | ( | C & | dest, |
| const C & | s1, | ||
| const C & | s2, | ||
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 238 of file modular_int.hpp.
References modulus_add_int_naive< V >::sub_mod().
{
dest = s1;
sub_mod (dest, s2, m, carry); }
| static void sub_mod | ( | C & | dest, |
| const C & | s, | ||
| const M & | m, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 229 of file modular_int.hpp.
References modulus_add_int_naive< V >::sub_mod_core().
{
sub_mod_core (dest, s, m.p, carry); }
| static void sub_mod_core | ( | C & | dest, |
| const C & | s, | ||
| const C & | p | ||
| ) | [inline, static, inherited] |
Definition at line 213 of file modular_int.hpp.
{
if (dest < s) dest += p;
dest -= s; }
| static void sub_mod_core | ( | C & | dest, |
| const C & | s, | ||
| const C & | p, | ||
| C & | carry | ||
| ) | [inline, static, inherited] |
Definition at line 218 of file modular_int.hpp.
References mmx::C.
{
VERIFY (carry == 0 || carry == 1, "unexpected large carry");
C t = s + carry;
if (t == p || dest < t) { dest += p; carry= 1; } else carry= 0;
dest -= t; }