EXTended NUMeric (EXTNUM)


SWBIC Products & Services >> Bioinformatics >> EXTNUM >> Available Constructors, Operators, & Functions


3. Available Constructors, Operators, and Functions

3.1 Constructors

The following list of constructors currently implemented in the EXTNUM class allow the user to declare and initialize EXTNUM variables:

  • extnum();
  • extnum(float m);
  • extnum(double m);
  • extnum(int m);
  • extnum(long m);
  • extnum(unsigned int m);
  • extnum(unsigned long m);
  • extnum(char m);
  • extnum(const char* m);
  • extnum(const extnum &E);

Another EXTNUM constructor is provided for internal use as a return value constructor for various operators and functions. It should be noted that the type long exponent parameter e is a base 2 exponent. This constructor performs a normalization operation as part of its execution:

  • extnum(double m, long e);
3.2 Conversion functions

For conversions of base 10 user input from parsed streams, a conversion member function is provided to construct an EXTNUM variable. This function is normally appropriate for internal use by the class:

  • extnum convert(double m, long e);

Simple conversions of EXTNUM values to built-in types are provided by the following operators (assuming that the EXTNUM value lies within the valid range of the target type):

  • operator float () const;
  • operator double () const;
  • operator int () const;
  • operator long () const;
  • operator unsigned int () const;
  • operator unsigned long () const;
3.3 Relational and logical operators

EXTNUM variables may be used in Boolean binary operations through the use of the following operators. Overloads to allow comparisons with type double variables are also provided:

  • friend bool operator==(extnum a, extnum b);
  • friend bool operator==(extnum a, double c);
  • friend bool operator==(double c, extnum b);
  • friend bool operator!=(extnum a, extnum b);
  • friend bool operator!=(extnum a, double c);
  • friend bool operator!=(double c, extnum b);
  • friend bool operator<(extnum l, extnum r);
  • friend bool operator<(extnum a, double c);
  • friend bool operator<(double c, extnum b);
  • friend bool operator>(extnum l, extnum r);
  • friend bool operator>(extnum a, double c);
  • friend bool operator>(double c, extnum b);
  • friend bool operator<=(extnum a, extnum b);
  • friend bool operator<=(extnum a, double c);
  • friend bool operator<=(double c, extnum b);
  • friend bool operator>=(extnum a, extnum b);
  • friend bool operator>=(extnum a, double c);
  • friend bool operator>=(double c, extnum b);
3.4 Mathematical functions

The fundamental unary and binary mathematical operations involving EXTNUM class variables are defined in the following instances:

  • friend extnum operator-(extnum a);
  • friend extnum operator+(extnum a, extnum b);
  • friend extnum operator+(extnum a, double c);
  • friend extnum operator+(double c, extnum b);
  • friend extnum operator-(extnum a, extnum b);
  • friend extnum operator-(extnum a, double c);
  • friend extnum operator-(double c, extnum b);
  • friend extnum operator*(extnum a, extnum b);
  • friend extnum operator*(extnum a, double c);
  • friend extnum operator*(double c, extnum b);
  • friend extnum operator/(extnum a, extnum b);
  • friend extnum operator/(extnum a, double c);
  • friend extnum operator/(double c, extnum b);

The EXTNUM class provides the following overloads for assignment and shorthand mathematical operators:

  • void operator=(const extnum& a);
  • void operator=(const double& c);
  • void operator+=(const double& c);
  • void operator+=(const extnum& a);
  • void operator-=(const double& c);
  • void operator-=(const extnum& a);
  • void operator*=(const double& c);
  • void operator*=(const extnum& a);
  • void operator/=(const double& c);
  • void operator/=(const extnum& a);

A number of common mathematical functions are supplied with the EXTNUM class:

  • friend extnum abs(extnum a);
  • friend extnum ceil(extnum a);
  • friend extnum floor(extnum a);
  • friend extnum pow(extnum x, double d);
  • friend extnum conj(extnum);
  • friend extnum exp(extnum x);
  • friend extnum sqrt(extnum x);
  • friend extnum log(extnum x);
  • friend extnum log10(extnum x);
3.5 Stream inserters/extractors

Conversion of input stream character data to EXTNUM variables and conversion of the internal EXTNUM representation to output streams are performed by the >> extractor and << inserter operator overloads for this class:

  • friend ostream &operator<<(ostream &stream, extnum a);
  • friend istream &operator>>(istream &stream, extnum &obj);