// Copyright (c) 2012 Vadym Kliuchnikov sqct(dot)software(at)gmail(dot)com, Dmitri Maslov, Michele Mosca
//
// This file is part of SQCT.
//
// SQCT is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SQCT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with SQCT. If not, see .
//
#include "resring.h"
template< int TMod>
resring::resring() :
v ( 0 )
{}
template< int TMod>
resring::resring(resring::int_type val)
{
set(val);
}
template< int TMod>
resring::resring(const mpz_class &val)
{
// note: works only for TMod = 8
int b0 = mpz_tstbit( val.get_mpz_t() , 0 );
int b1 = mpz_tstbit( val.get_mpz_t() , 1 );
int b2 = mpz_tstbit( val.get_mpz_t() , 2 );
v = 0;
v |= b2;
v <<= 1;
v |= b1;
v <<= 1;
v |= b0;
}
template< int TMod>
resring& resring::operator +=(const resring& y)
{
set( v + y.v );
return *this;
}
template< int TMod>
resring& resring::operator -=(const resring& y)
{
set( v - y.v );
return *this;
}
template< int TMod>
bool resring::operator <(const resring &y) const
{
return v < y.v;
}
template< int TMod>
bool resring::operator >(const resring &y) const
{
return v > y.v;
}
template< int TMod>
resring resring::operator +(const resring &y) const
{
return resring( y.v + v );
}
template< int TMod>
resring resring::operator -(const resring &y) const
{
return resring( v - y.v );
}
template< int TMod>
resring resring::operator -() const
{
return resring( -v );
}
template< int TMod>
resring resring::operator *(const resring &y) const
{
return resring( y.v * v );
}
template< int TMod>
resring resring::operator /(const resring &e) const
{
return resring( v / e.v );
}
template< int TMod>
resring &resring::operator /=(const resring &e)
{
set( v /= e.v );
}
template< int TMod>
resring &resring::operator <<=(int e)
{
set( v << e );
}
template< int TMod>
resring resring::operator >> (int e ) const
{
return resring( v >> e );
}
template< int TMod>
resring &resring::operator >>=(int e)
{
v >>= e;
}
template< int TMod>
typename resring::int_type resring::operator %(int e)
{
return v % e;
}
template< int TMod>
resring::operator int_type() const
{
return v;
}
template< int TMod>
void resring::set(resring::int_type val)
{
v = mod(val);
}
template< int TMod>
typename resring::int_type resring::mod(resring::int_type val)
{
return ( val % TMod + 2 * TMod ) % TMod;
}
template< int TMod>
bool resring::operator ==(const resring &y) const
{
return v == y.v;
}
template< int TMod>
bool resring::operator !=(const resring &y) const
{
return v != y.v;
}
//// template compilation request
template class resring<8>;