Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends

chomp::homology::integer Class Reference

This class defines integer numbers with overflow control and with some specific properties of an Euclidean domain. More...

#include <integer.h>

List of all members.

Public Member Functions

integeroperator= (int n)
int delta (void) const
integer normalized () const
integer operator- () const
integeroperator+= (const integer &n)
integeroperator*= (const integer &n)
integer operator+ (const integer &n) const
integer operator* (const integer &n) const
integer operator/ (const integer &n) const
integer operator% (const integer &n) const
int operator== (const integer &n) const

Static Public Member Functions

static int initialize (int n)
static const char * ringname ()
static const char * ringsymbol ()

Static Protected Member Functions

static int cut_down (int n)
static int is_prime (int n)
static int prime_number (int n)
static unsigned invert (unsigned n, unsigned q)

Protected Attributes

numbertype num

Static Protected Attributes

static int p

Friends

std::ostream & operator<< (std::ostream &out, const integer &n)
bool operator< (const integer &x, const integer &y)
bool operator> (const integer &x, const integer &y)

Detailed Description

This class defines integer numbers with overflow control and with some specific properties of an Euclidean domain.

Note that this class has very few features which are limited on purpose to optimize it for application in a chain complex class for homology computation.

Definition at line 134 of file integer.h.


Member Function Documentation

int chomp::homology::integer::cut_down ( int  n  )  [inline, static, protected]

Definition at line 195 of file integer.h.

References num, and p.

Referenced by operator=().

{
        if (n >= 0)
                if (n < p)
                        return n;
                else
                        return (n % p);
        else
        {
                int num = p - ((-n) % p);
                if (num == p)
                        return 0;
                else
                        return num;
        }
} /* cut_down */

int chomp::homology::integer::delta ( void   )  const [inline]

Definition at line 394 of file integer.h.

References num, and p.

{
        if (p)
                return (num ? 1 : 0);
        else
                return ((num >= 0) ? num : -num);
} /* integer::delta */

int chomp::homology::integer::initialize ( int  n  )  [inline, static]

Definition at line 388 of file integer.h.

References p, and prime_number().

{
        p = prime_number (n);
        return p;
} /* integer::initialize */

static unsigned chomp::homology::integer::invert ( unsigned  n,
unsigned  q 
) [static, protected]

Referenced by operator/().

static int chomp::homology::integer::is_prime ( int  n  )  [static, protected]
integer chomp::homology::integer::normalized ( void   )  const [inline]

Definition at line 402 of file integer.h.

References num.

{
        integer n;
        if (num < 0)
                n. num = (numbertype) (-num);
        else
                n. num = num;
        return n;
} /* integer::normalized */

integer chomp::homology::integer::operator% ( const integer n  )  const [inline]

Definition at line 265 of file integer.h.

References num, and p.

{
        integer result;
        if (p)
                result. num = 0;
        else
                result = num % n. num;
        return result;
} /* operator % */

integer chomp::homology::integer::operator* ( const integer n  )  const [inline]

Definition at line 338 of file integer.h.

{
        integer m (n);
        m *= *this;
        return m;
} /* operator * */

integer & chomp::homology::integer::operator*= ( const integer n  )  [inline]

Definition at line 307 of file integer.h.

References num, and p.

{
        if (p)
        {
                long result = (long) num * (long) n. num;
                if (result >= 0)
                        num = (numbertype) (result % p);
                else
                {
                        num = (numbertype) (p - ((-result) % p));
                        if (num == p)
                                num = 0;
                }
        }
        else
        {
                long result = (long) num * (long) (n. num);
                num = (numbertype) result;
                if ((long) num != result)
                        throw "Number out of range (*).";
        }
        return *this;
} /* integer::operator *= */

integer chomp::homology::integer::operator+ ( const integer n  )  const [inline]

Definition at line 331 of file integer.h.

{
        integer m (n);
        m += *this;
        return m;
} /* operator + */

integer & chomp::homology::integer::operator+= ( const integer n  )  [inline]

Definition at line 294 of file integer.h.

References num, and p.

{
        if (!p)
                if (((n. num >= 0) && (num + n. num < num)) ||
                        ((n. num < 0) && (num + n. num > num)))
                        throw "Number out of range (+).";
        num += n. num;
        if (p)
                if (num >= p)
                        num -= (numbertype) p;
        return *this;
} /* integer::operator += */

integer chomp::homology::integer::operator- (  )  const [inline]

Definition at line 275 of file integer.h.

References num, and p.

{
        if (p)
        {
                integer negative;
                negative. num = (numbertype) (p - num);
                return negative;
        }
        else
        {
                numbertype result = (numbertype) -num;
                if ((long) result + (long) num != 0)
                        throw "Number out of range (unary -).";
                integer intresult;
                intresult = result;
                return intresult;
        }
} /* integer::operator - (unary) */

integer chomp::homology::integer::operator/ ( const integer n  )  const [inline]

Definition at line 255 of file integer.h.

References invert(), num, and p.

{
        integer result;
        if (p)
                result = num * (int) invert (n. num, p);
        else
                result. num = (numbertype) (num / n. num);
        return result;
} /* integer::operator / */

integer & chomp::homology::integer::operator= ( int  n  )  [inline]

Definition at line 242 of file integer.h.

References cut_down(), num, and p.

{
        if (p)
                num = (numbertype) cut_down (n);
        else
        {
                num = (numbertype) n;
                if ((long) num != (long) n)
                        throw "Number out of range at assignment.";
        }
        return *this;
} /* integer::operator = */

int chomp::homology::integer::operator== ( const integer n  )  const [inline]

Definition at line 345 of file integer.h.

References num.

{
        return (n. num == num);
} /* operator == */

static int chomp::homology::integer::prime_number ( int  n  )  [static, protected]

Referenced by initialize().

static const char* chomp::homology::integer::ringname (  )  [static]
static const char* chomp::homology::integer::ringsymbol (  )  [static]

Friends And Related Function Documentation

bool operator< ( const integer x,
const integer y 
) [friend]

Definition at line 412 of file integer.h.

{
        return (x. num < y. num);
} /* operator < */

std::ostream& operator<< ( std::ostream &  out,
const integer n 
) [friend]

Definition at line 350 of file integer.h.

{
        out << (long) n. num;
        return out;
} /* operator << */

bool operator> ( const integer x,
const integer y 
) [friend]

Definition at line 417 of file integer.h.

{
        return (x. num > y. num);
} /* operator > */


Member Data Documentation

int chomp::homology::integer::p [static, protected]

The documentation for this class was generated from the following file: