Double Class Reference

My own Double class wrapper. More...

#include <Double.h>


Public Member Functions

 Double ()
 Main constructor.
 Double (const char *_string)
 Creates a Double from a const char* string.
 Double (const DString &newString)
 Creates a Double from a DString.
 Double (const double newDouble)
 Main constructor.
 Double (const double, const double, const double)
 Triplet Double Constructor.
 Double (const int i)
 Int to Double constructor.
 Double (const Double &)
 Copy Constructor.
Double operator+ (const Double &)
 Adds Double components.
Double operator+ (const double &)
 The provided double is added to the first element in the Double class.
void operator+= (const Double &)
void operator+= (const double)
Double operator- (const Double &)
 Subtracts the Double classes.
Double operator- (const double &)
 Subtracts the provided double from the first double element.
void operator-= (const Double &)
void operator-= (const double)
bool operator!= (const Double &rhs) const
 Compares each doubleValue independently, according to: mydoubleValue != rhs.doubleValue() || mydoubleValue2 != rhs.getValue(1) || mydoubleValue3 != rhs.getValue(2).
bool operator!= (const double rhs) const
 Compares each doubleValue independently, according to: mydoubleValue != rhs.doubleValue() || mydoubleValue2 != rhs.getValue(1) || mydoubleValue3 != rhs.getValue(2).
void operator*= (const Double &)
 Multiplies Double elements as a vector inner (dot) product.
void operator*= (const double)
Doubleoperator= (const Double &)
Doubleoperator= (const double &)
bool operator== (const Double &) const
bool operator== (const double) const
bool operator<= (const double f) const
 Compares the first elements in the double.
bool operator<= (const int f) const
 Compares the first elements in the double.
bool operator<= (const Double &f) const
 Compares the first elements in the double.
bool operator>= (const double f) const
 Compares the first elements in the double.
bool operator>= (const int f) const
 Compares the first elements in the double.
bool operator>= (const Double &f) const
 Compares the first elements in the double.
bool operator< (const Double &f) const
 Compares the first elements in the double.
bool operator< (const double f) const
 Compares the first elements in the double.
bool operator> (const Double &f) const
 Compares the first elements in the double.
bool operator> (const double f) const
 Compares the first elements in the double.
 operator DString () const
 Casts the double to a DString, using toDString();.
Double operator* (const Double &f)
 Multiplication is performed where each of the 3 components are linearly independent and multiplication is done as an inner product.
Double operator* (const double f)
Double operator/ (const double f)
double doubleValue () const
 Gives the double value of the Double's first element.
DString toDString () const
 Gives a DString representation of the Double (first value).
DString toDString (std::ostringstream &ss) const
 Like toDString(), but provides use of an optional, external stream for conversion.
int sign () const
int sgn () const
int intValue () const
 Gives the integer part of the real value in the double.
int toInt ()
 Casts the double as an int.
double modulus () const
 Gives the modulus(absolute value) of the Double.
double getValue (int inty) const
 Gives the inty-th value of the Double wrapper.
void setValue (int inty, double value)
 Sets the inty-th value of the Double wrapper.

Static Public Member Functions

static double exponent (double i, int power)
 Gives the value of i to the provided power.
static bool isDouble (const char *)
 Determines if the string is a double.
static bool isDouble (const DString &)
 Determines if the string is a double.
static int getIntVal (char ch)
 Gives the ASCII value of the provided character.
static int sign (const double d)
 Gives the sign of the provided double Note: sign(0) = 0;.
static int sgn (const double d)
static double parseRoot (double base, double n)
 Gives the n-th root of the provided base.
static int hexToInt (DString &)
 DEPRECATED (too slow): Converts the provided Hexadecimal DString to a number.
static DString intToHex (const int)
 DEPRECATED(too slow): Converts an integer to a hexadecimal number.
static int stringToNBase (DString number, int base)
 Changes the string to the provied base.
static Double parseDString (const DString &newString)
 Parses a DString to a double Note: if the string is not a valid, real number, a DavidException is thrown.
static double e (const double &x)
 Calculates the exponential function.

Private Attributes

double mydoubleValue
double mydoubleValue2
double mydoubleValue3

Friends

std::ostream & operator<< (std::ostream &, const Double &)


Detailed Description

My own Double class wrapper.

Contains 3 doubles. This provides a convenient way of handling 3D coordinates. This class is capable of parsing a string (and/or DString). Copyright 2010 David Coss Copying and distributing are permitted under the terms of the GNU Public License version 3 (see COPYING or http://www.gnu.org/licenses/gpl.txt).


Constructor & Destructor Documentation

Double::Double (  )  [inline]

Main constructor.

By default the double values are zero.

References mydoubleValue, mydoubleValue2, and mydoubleValue3.

Referenced by getValue(), intToHex(), isDouble(), parseDString(), and setValue().

Double::Double ( const char *  _string  ) 

Creates a Double from a const char* string.

Note: if the string is not a valid real number, a DavidException is thrown.

Parameters:
_string String given
See also:
Double(const DString& newString)
Exceptions:
DavidException. 

References DavidException::FORMAT_ERROR_CODE, mydoubleValue, mydoubleValue2, and mydoubleValue3.

Double::Double ( const DString newString  ) 

Creates a Double from a DString.

Note: if the string is not a valid real number, a DavidException is thrown.

Parameters:
newString String given
See also:
Double(const char * _string)
Exceptions:
DavidException. 

References DString::contains(), DavidException::FORMAT_ERROR_CODE, DString::getString(), mydoubleValue, mydoubleValue2, and mydoubleValue3.

Double::Double ( const double  newDouble  ) 

Main constructor.

Creates a Double wrapper for the supplied double.

Parameters:
newDouble. 

References mydoubleValue, mydoubleValue2, and mydoubleValue3.

Double::Double ( const double  i,
const double  i2,
const double  i3 
)

Triplet Double Constructor.

This constructor creates a Double wrapper that can hold three doubles.

References mydoubleValue, mydoubleValue2, and mydoubleValue3.

Double::Double ( const int  i  )  [inline]

Int to Double constructor.

This constructor casts the provided int as a double and stores it.

Parameters:
i int given to become a Double.

References mydoubleValue, mydoubleValue2, and mydoubleValue3.

Double::Double ( const Double f  ) 

Copy Constructor.

References getValue(), mydoubleValue, mydoubleValue2, and mydoubleValue3.


Member Function Documentation

double Double::doubleValue (  )  const [inline]

Gives the double value of the Double's first element.

Returns:
double.

References mydoubleValue.

Referenced by hexToInt(), operator!=(), operator<(), operator<=(), operator=(), operator>(), and operator>=().

static double Double::e ( const double &  x  )  [inline, static]

Calculates the exponential function.

double Double::exponent ( double  i,
int  power 
) [static]

Gives the value of i to the provided power.

Parameters:
i base.
power 
Returns:
double

References DavidException::FORMAT_ERROR_CODE.

Referenced by math::Binary::Binary(), hexToInt(), and math::Binary::operator~().

int Double::getIntVal ( char  ch  )  [static]

Gives the ASCII value of the provided character.

Parameters:
ch 
Returns:
int

References DavidException::FORMAT_ERROR_CODE.

double Double::getValue ( int  inty  )  const

Gives the inty-th value of the Double wrapper.

Note: USUALLY the double only contains one value, so "0" would be used. However, if the double is used to hold 3 doubles, then use either 0, 1, or 2. An index greater than 2 or less than 0 will cause a DavidException to be thrown.

Parameters:
inty zero index.
Returns:
double
See also:
setValue(int inty, double value)
Exceptions:
DavidException. 

References Double(), mydoubleValue, mydoubleValue2, mydoubleValue3, and toDString().

Referenced by math::Complex::Complex(), Double(), operator!=(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator=(), math::Complex::operator=(), operator==(), and math::Complex::operator==().

int Double::hexToInt ( DString hex  )  [static]

DEPRECATED (too slow): Converts the provided Hexadecimal DString to a number.

Note: If the string is not a valid hexadecimal number, a DavidException is thrown.

Returns:
int
See also:
DavidException

intToHex(const int)

References DString::contains(), DEBUG_PRINT, doubleValue(), exponent(), DavidException::FORMAT_ERROR_CODE, DString::length(), and ushort.

DString Double::intToHex ( const int  arg  )  [static]

DEPRECATED(too slow): Converts an integer to a hexadecimal number.

Returns:
DString.

References Double(), and DavidException::INVALID_ARGUMENT_ERROR_CODE.

int Double::intValue (  )  const

Gives the integer part of the real value in the double.

To be used in lieu of (int) casting.

References mydoubleValue.

Referenced by toInt().

bool Double::isDouble ( const DString bean  )  [static]

Determines if the string is a double.

Returns:
bool
See also:
isDouble(const char *)

References Double(), DavidException::FORMAT_ERROR_CODE, and DavidException::getCode().

bool Double::isDouble ( const char *  bean  )  [static]

Determines if the string is a double.

Returns:
bool
See also:
isDouble(DString&)

double Double::modulus (  )  const

Gives the modulus(absolute value) of the Double.

Returns:
double.

References mydoubleValue, mydoubleValue2, and mydoubleValue3.

Double::operator DString (  )  const [inline]

Casts the double to a DString, using toDString();.

References toDString().

bool Double::operator!= ( const double  rhs  )  const [inline]

Compares each doubleValue independently, according to: mydoubleValue != rhs.doubleValue() || mydoubleValue2 != rhs.getValue(1) || mydoubleValue3 != rhs.getValue(2).

References mydoubleValue.

bool Double::operator!= ( const Double rhs  )  const [inline]

Compares each doubleValue independently, according to: mydoubleValue != rhs.doubleValue() || mydoubleValue2 != rhs.getValue(1) || mydoubleValue3 != rhs.getValue(2).

References doubleValue(), getValue(), mydoubleValue, mydoubleValue2, and mydoubleValue3.

Double Double::operator* ( const double  f  ) 

Double Double::operator* ( const Double f  ) 

Multiplication is performed where each of the 3 components are linearly independent and multiplication is done as an inner product.

References getValue(), and setValue().

void Double::operator*= ( const double  i  ) 

References getValue(), and setValue().

void Double::operator*= ( const Double i  ) 

Multiplies Double elements as a vector inner (dot) product.

References getValue(), and setValue().

Double Double::operator+ ( const double &  j  ) 

The provided double is added to the first element in the Double class.

References getValue(), mydoubleValue, and setValue().

Double Double::operator+ ( const Double j  ) 

Adds Double components.

Each element is treated as linearly independent.

References getValue(), and setValue().

void Double::operator+= ( const double  j  ) 

References mydoubleValue, and setValue().

void Double::operator+= ( const Double j  ) 

See also:
operator+(const Double&)

References getValue(), and setValue().

Double Double::operator- ( const double &  j  ) 

Subtracts the provided double from the first double element.

References getValue(), mydoubleValue, and setValue().

Double Double::operator- ( const Double j  ) 

Subtracts the Double classes.

See also:
operator+(const Double&)

References getValue(), and setValue().

void Double::operator-= ( const double  j  ) 

References mydoubleValue, and setValue().

void Double::operator-= ( const Double j  ) 

References getValue(), and setValue().

Double Double::operator/ ( const double  f  ) 

bool Double::operator< ( const double  f  )  const [inline]

Compares the first elements in the double.

References mydoubleValue.

bool Double::operator< ( const Double f  )  const [inline]

Compares the first elements in the double.

References doubleValue(), and mydoubleValue.

bool Double::operator<= ( const Double f  )  const [inline]

Compares the first elements in the double.

References doubleValue(), and mydoubleValue.

bool Double::operator<= ( const int  f  )  const [inline]

Compares the first elements in the double.

References mydoubleValue.

bool Double::operator<= ( const double  f  )  const [inline]

Compares the first elements in the double.

References mydoubleValue.

Double & Double::operator= ( const double &  d  ) 

Double & Double::operator= ( const Double j  ) 

bool Double::operator== ( const double  j  )  const

References mydoubleValue.

bool Double::operator== ( const Double j  )  const

References getValue().

bool Double::operator> ( const double  f  )  const [inline]

Compares the first elements in the double.

References mydoubleValue.

bool Double::operator> ( const Double f  )  const [inline]

Compares the first elements in the double.

References doubleValue(), and mydoubleValue.

bool Double::operator>= ( const Double f  )  const [inline]

Compares the first elements in the double.

References doubleValue(), and mydoubleValue.

bool Double::operator>= ( const int  f  )  const [inline]

Compares the first elements in the double.

References mydoubleValue.

bool Double::operator>= ( const double  f  )  const [inline]

Compares the first elements in the double.

References mydoubleValue.

Double Double::parseDString ( const DString newString  )  [static]

Parses a DString to a double Note: if the string is not a valid, real number, a DavidException is thrown.

Parameters:
newString String to be converted to a Double.
Returns:
Double.
Exceptions:
DavidException. 

References Double().

double Double::parseRoot ( double  base,
double  n 
) [static]

Gives the n-th root of the provided base.

Parameters:
base. 
n 
Returns:
double.

References DavidException::IMAGINARY_NUMBER_ERROR_CODE.

void Double::setValue ( int  inty,
double  value 
)

Sets the inty-th value of the Double wrapper.

Note: USUALLY the double only contains one value, so "0" would be used. However, if the double is used to hold 3 doubles, then use either 0, 1, or 2. An index greater than 2 or less than 0 will cause a DavidException to be thrown.

Parameters:
inty zero index.
value new double value for the inty-th index.
Returns:
double
See also:
getValue(int inty)
Exceptions:
DavidException. 

References Double(), mydoubleValue, mydoubleValue2, mydoubleValue3, and toDString().

Referenced by operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), and operator/().

int Double::sgn (  )  const [inline]

References sign().

static int Double::sgn ( const double  d  )  [inline, static]

References sign().

int Double::sign (  )  const [inline]

References mydoubleValue, and sign().

Referenced by sgn(), and sign().

int Double::sign ( const double  d  )  [static]

Gives the sign of the provided double Note: sign(0) = 0;.

Parameters:
double d
Returns:
int +-1 or 0

int Double::stringToNBase ( DString  number,
int  base 
) [static]

Changes the string to the provied base.

DString Double::toDString ( std::ostringstream &  ss  )  const

Like toDString(), but provides use of an optional, external stream for conversion.

The string version of the Double is left in the stream.

References mydoubleValue.

DString Double::toDString (  )  const

Gives a DString representation of the Double (first value).

Returns:
DString.

Referenced by getValue(), operator DString(), operator<<(), and setValue().

int Double::toInt (  ) 

Casts the double as an int.

Returns:
int

References DavidException::FORMAT_ERROR_CODE, and intValue().


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  theStream,
const Double j 
) [friend]


Field Documentation

double Double::mydoubleValue [private]

double Double::mydoubleValue2 [private]

double Double::mydoubleValue3 [private]


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

Generated on Fri Jun 11 21:02:35 2010 for libdnstd by  doxygen 1.5.7.1