// ============================================================ // // traitsI.h // // Copyright 2002, Dennis Meilicke and Rene Peralta // // ============================================================ // // Description: // // Implementation of the traits class. // // ============================================================ #ifndef __nttl_traitsI__ #define __nttl_traitsI__ #include using namespace std; // // This shouldn't be here. Where should the bool type go? // #ifdef _AIX #include #endif #include // // Note: // // The Mod8 and Mod4 methods should be changed to do a // bitwise 'and', as soon as this is implemented in ln3. // template inline T nttlTraits::Random( size_t digits ) { return rand( ); } #ifndef _AIX template inline T nttlTraits::RandomMod( T m ) { return ( rand( ) % m ); } #endif template inline T nttlTraits::Square( const T& x ) { return x * x; } template inline short nttlTraits::Mod8( const T& x ) { return x % 8; } template inline short nttlTraits::Mod4( const T& x ) { return x % 4; } template inline bool nttlTraits::IsOdd( const T &x ) { return ( ( x & 1 ) == 1 ); } template inline bool nttlTraits::IsEven( const T &x ) { return ( ( x & 1 ) == 0 ); } template inline T nttlTraits::Abs( const T &X ) { return ( X < 0 ) ? -X : X; } template inline T nttlTraits::Power( T X, T e ) { T P = 1; for( ; e != 0 ; e >>= 1 ) { if( IsOdd( e ) ) P = P * X; X = Square( X ); } return P; } template inline T nttlTraits::Power( T X, T e, const T &m ) { T P = 1; for( ; e != 0 ; e >>= 1 ) { if( IsOdd( e ) ) P = P * X % m; X = Square( X ) % m; } return P; } template inline size_t nttlTraits::DecimalDigits( const T& x ) { ostringstream ostr; ostr << x << ends; size_t length = ostr.str( ).size; return length; } template inline short ToShort( const T& X ) { short x; x = X & 0xefff; if( X < 0 ) x = -x; return x; } template inline long ToLong( const T& X ) { long x; x = X & 0xefffffff; if( X < 0 ) x = -x; return x; } template inline unsigned short ToUnsignedShort( const T& X ) { unsigned short x; x = X & 0xffff; return x; } template inline unsigned long ToUnsignedLong( const T& X ) { unsigned long x; x = X & 0xffffffff; return x; } #endif // __nttl_traitsI__