📄 flintpp.cpp
字号:
return (testbit_l (n_l, pos));
}
////////////////////////////////////////////////////////////////////////////////
// Swapping, purging //
////////////////////////////////////////////////////////////////////////////////
// member-swap
LINT& LINT::fswap (LINT& b)
{
LINT tmp;
if (status == E_LINT_INV) panic (E_LINT_INV, "fswap", 0, __LINE__);
if (b.status == E_LINT_INV) panic (E_LINT_INV, "fswap", 1, __LINE__);
tmp = *this;
*this = b;
b = tmp;
return *this;
}
// friend-swap
void fswap (LINT& a, LINT& b)
{
LINT tmp;
if (a.status == E_LINT_INV) LINT::panic (E_LINT_INV, "fswap", 1, __LINE__);
if (b.status == E_LINT_INV) LINT::panic (E_LINT_INV, "fswap", 2, __LINE__);
tmp = a;
a = b;
b = tmp;
}
// Purging of LINT variables, overwriting with 0
void LINT::purge (void)
{
if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "purge", 0, __LINE__);
purge_l (n_l); //lint !e613
SETDIGITS_L (n_l, 0); //lint !e613
status = E_LINT_INV;
}
// friend-purge
void purge (LINT& a)
{
if (a.status == E_LINT_INV) LINT::panic (E_LINT_INV, "purge", 1, __LINE__);
purge_l (a.n_l); //lint !e613
SETDIGITS_L (a.n_l, 0); //lint !e613
a.status = E_LINT_INV;
}
////////////////////////////////////////////////////////////////////////////////
// Arithmetic member functions //
// Accumulator mode //
////////////////////////////////////////////////////////////////////////////////
const LINT& LINT::add (const LINT& b)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "add", 0, __LINE__);
if (b.status == E_LINT_INV) panic (E_LINT_INV, "add", 1, __LINE__);
err = add_l (n_l, b.n_l, n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_OFL:
status = E_LINT_OFL;
break;
default:
panic (E_LINT_ERR, "add", err, __LINE__);
}
return *this;
}
const LINT& LINT::sub (const LINT& b)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "sub", 0, __LINE__);
if (b.status == E_LINT_INV) panic (E_LINT_INV, "sub", 1, __LINE__);
err = sub_l (n_l, b.n_l, n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_UFL:
status = E_LINT_UFL;
break;
default:
panic (E_LINT_ERR, "sub", err, __LINE__);
}
return *this;
}
const LINT& LINT::mul (const LINT& b)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mul", 0, __LINE__);
if (b.status == E_LINT_INV) panic (E_LINT_INV, "mul", 1, __LINE__);
if (&b == this)
err = sqr_l (n_l, n_l);
else
err = mul_l (n_l, b.n_l, n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_OFL:
status = E_LINT_OFL;
break;
default:
panic (E_LINT_ERR, "mul", err, __LINE__);
}
return *this;
}
const LINT& LINT::sqr (void)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "sqr", 0, __LINE__);
err = sqr_l (n_l, n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_OFL:
status = E_LINT_OFL;
break;
default:
panic (E_LINT_ERR, "sqr", err, __LINE__);
}
return *this;
}
const LINT& LINT::divr (const LINT& d, LINT& r)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "divr", 0, __LINE__);
if (d.status == E_LINT_INV) panic (E_LINT_INV, "divr", 1, __LINE__);
err = div_l (n_l, d.n_l, n_l, r.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
r.status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "divr", 1, __LINE__);
break;
default:
panic (E_LINT_ERR, "divr", err, __LINE__);
}
return *this;
}
const LINT& LINT::mod (const LINT& d)
{
LINT junk;
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mod", 0, __LINE__);
if (d.status == E_LINT_INV) panic (E_LINT_INV, "mod", 1, __LINE__);
err = div_l (n_l, d.n_l, junk.n_l, n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "mod", 1, __LINE__);
break;
default:
panic (E_LINT_ERR, "mod", err, __LINE__);
}
return *this;
}
const LINT& LINT::mod2 (USHORT m) // mod 2^m
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mod2", 0, __LINE__);
err = mod2_l (n_l, m, n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
default:
panic (E_LINT_ERR, "mod2", err, __LINE__);
}
return *this;
}
const LINT& LINT::madd (const LINT& ln, const LINT& m)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "madd", 0, __LINE__);
if (ln.status == E_LINT_INV) panic (E_LINT_INV, "madd", 1, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "madd", 2, __LINE__);
err = madd_l (n_l, ln.n_l, n_l, m.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "madd", 2, __LINE__);
break;
default:
panic (E_LINT_ERR, "madd", err, __LINE__);
}
return *this;
}
const LINT& LINT::msub (const LINT& ln, const LINT& m)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "msub", 0, __LINE__);
if (ln.status == E_LINT_INV) panic (E_LINT_INV, "msub", 1, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "msub", 2, __LINE__);
err = msub_l (n_l, ln.n_l, n_l, m.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "msub", 2, __LINE__);
break;
default:
panic (E_LINT_ERR, "msub", err, __LINE__);
}
return *this;
}
const LINT& LINT::mmul (const LINT& ln, const LINT& m)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mmul", 0, __LINE__);
if (ln.status == E_LINT_INV) panic (E_LINT_INV, "mmul", 1, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "mmul", 2, __LINE__);
if (&ln == this)
err = msqr_l (n_l, n_l, m.n_l);
else
err = mmul_l (n_l, ln.n_l, n_l, m.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "mmul", 2, __LINE__);
break;
default:
panic (E_LINT_ERR, "mmul", err, __LINE__);
}
return *this;
}
const LINT& LINT::msqr (const LINT& m)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "msqr", 0, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "msqr", 1, __LINE__);
err = msqr_l (n_l, n_l, m.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "msqr", 1, __LINE__);
break;
default:
panic (E_LINT_ERR, "msqr", err, __LINE__);
}
return *this;
}
const LINT& LINT::mexp (USHORT e, const LINT& m)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mexp", 0, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "mexp", 1, __LINE__);
if (m.isodd ())
{
err = umexpm_l (n_l, e, n_l, m.n_l);
}
else
{
err = umexp_l (n_l, e, n_l, m.n_l);
}
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "mexp", 2, __LINE__);
break;
default:
panic (E_LINT_ERR, "mexp", err, __LINE__);
}
return *this;
}
const LINT& LINT::mexp (const LINT& ln, const LINT& m)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mexp", 0, __LINE__);
if (ln.status == E_LINT_INV) panic (E_LINT_INV, "mexp", 1, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "mexp", 2, __LINE__);
err = mexp_l (n_l, ln.n_l, n_l, m.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "mexp", 2, __LINE__);
break;
default:
panic (E_LINT_ERR, "mexp", err, __LINE__);
}
return *this;
}
const LINT& LINT::mexp5m (const LINT& ln, const LINT& m)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mexp5m", 0, __LINE__);
if (ln.status == E_LINT_INV) panic (E_LINT_INV, "mexp5m", 1, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "mexp5m", 2, __LINE__);
err = mexp5m_l (n_l, ln.n_l, n_l, m.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_MOD:
panic (E_LINT_MOD, "mexp5m", 2, __LINE__);
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "mexp5m", 2, __LINE__);
break;
default:
panic (E_LINT_ERR, "mexp5m", err, __LINE__);
}
return *this;
}
const LINT& LINT::mexpkm (const LINT& ln, const LINT& m)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mexpkm", 0, __LINE__);
if (ln.status == E_LINT_INV) panic (E_LINT_INV, "mexpkm", 1, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "mexpkm", 2, __LINE__);
err = mexpkm_l (n_l, ln.n_l, n_l, m.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_MOD:
panic (E_LINT_MOD, "mexpkm", 2, __LINE__);
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "mexpkm", 2, __LINE__);
break;
default:
panic (E_LINT_ERR, "mexpkm", err, __LINE__);
}
return *this;
}
const LINT& LINT::mexp2 (USHORT e, const LINT& m) // *this^(2^e)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "mexp2", 0, __LINE__);
if (m.status == E_LINT_INV) panic (E_LINT_INV, "mexp2", 1, __LINE__);
err = mexp2_l (n_l, e, n_l, m.n_l);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_DBZ:
panic (E_LINT_DBZ, "mexp2", 2, __LINE__);
break;
default:
panic (E_LINT_ERR, "mexp2", err, __LINE__);
}
return *this;
}
const LINT& LINT::shift (int noofbits)
{
int err;
if (status == E_LINT_INV) panic (E_LINT_INV, "shift", 0, __LINE__);
err = shift_l (n_l, noofbits);
switch (err)
{
case E_CLINT_OK:
status = E_LINT_OK;
break;
case E_CLINT_OFL:
status = E_LINT_OFL;
break;
case E_CLINT_UFL:
status = E_LINT_UFL;
break;
default:
panic (E_LINT_ERR, "shift", err, __LINE__);
}
return *this;
}
////////////////////////////////////////////////////////////////////////////////
// Number-theoretic member functions //
////////////////////////////////////////////////////////////////////////////////
unsigned int LINT::ld (void) const
{
if (status == E_LINT_INV) panic (E_LINT_INV, "ld", 0, __LINE__);
return ld_l (n_l);
}
int LINT::iseven (void) const
{
if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "iseven", 0, __LINE__);
return (ISEVEN_L (n_l)); //lint !e613
}
int LINT::isodd (void) const
{
if (status == E_LINT_INV) LINT::panic (E_LINT_INV, "isodd", 0, __LINE__);
return (ISODD_L (n_l)); //lint !e613
}
int LINT::isprime (int noofsmallprimes, int iterations) const
{
if (status == E_LINT_INV) panic (E_LINT_INV, "isprime", 0, __LINE__);
return (prime_l (n_l, noofsmallprimes, iterations));
}
LINT LINT::issqr (void) const
{
LINT sqroot;
if (status == E_LINT_INV) panic (E_LINT_INV, "issqr", 0, __LINE__);
issqr_l (n_l, sqroot.n_l);
sqroot.status = E_LINT_OK;
return sqroot;
}
LINT LINT::root (void) const
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -