Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

mcRationalValue Class Reference

#include <Value.h>

Inheritance diagram for mcRationalValue:

Inheritance graph
[legend]
Collaboration diagram for mcRationalValue:

Collaboration graph
[legend]
List of all members.

Detailed Description

A rational value stored internally by GMP in the form of two mcIntegerValues representing the numerator and denominator.

Thus, numbers like 2/3 = 0.6666... can be stored without rounding and be approximated to any desired precision.

Definition at line 583 of file Value.h.

Public Member Functions

 mcVALUE_DEFINE_CONSTRUCTORS (mcRationalValue, mcMPQ)
 mcRationalValue (const mcIntegerValue &m)
 mcRationalValue (const mcRealValue &m)
 mcRationalValue (const mcIntegerValue &num, const mcIntegerValue &den)
mcIntegerValue GetDen () const
mcIntegerValue GetNum () const
void Canonicalize ()
 Remove any factors that are common to the numerator and denominator and make the denominator positive.
 mcVALUE_DEFINE_SETGET_FLAGS ()
 mcVALUE_DEFINE_MISCELLANEOUS (mcRationalValue, mpq)
void SetLong (long n)
void SetDouble (double n)
void SetStr (const wxString &str, int base=10)
double GetDouble () const
long GetLong () const
wxString GetStr () const
 See mcValue::GetStr.
bool isInteger () const
 Returns TRUE if the denominator of this number is 1.
mcRationalValue abs () const
 Returns the absolute value of this number.
mcRationalValue GetFractionalPart () const
 Returns the fractional part of this number, removing the integer one.
int GetFractionalDigitCount (int digits=mcVALUE_DEFAULTPRECISION) const
 Returns the number of fractional digits.
mcIntegerValue GetIntegerPart () const
 Returns the integer part of this number, removing the fractional one.
mcIntegerValue MakeInteger (int digits=mcVALUE_DEFAULTPRECISION) const
 Transform a copy of this number multiplying it by 10^GetFractionalDigitCount(*this), thus transforming it into an integer number.

Private Member Functions

 mcVALUE_DEFINE_COW (mcMPQ, mpq)


Constructor & Destructor Documentation

mcRationalValue::mcRationalValue const mcIntegerValue m  ) 
 

Definition at line 172 of file Value.cpp.

mcRationalValue::mcRationalValue const mcRealValue m  ) 
 

Definition at line 175 of file Value.cpp.

mcRationalValue::mcRationalValue const mcIntegerValue num,
const mcIntegerValue den
 

Definition at line 178 of file Value.cpp.


Member Function Documentation

mcRationalValue mcRationalValue::abs  )  const [inline]
 

Returns the absolute value of this number.

Definition at line 625 of file Value.h.

void mcRationalValue::Canonicalize  )  [inline]
 

Remove any factors that are common to the numerator and denominator and make the denominator positive.

Definition at line 601 of file Value.h.

Referenced by mcNumberHelpers::math_GetNumDen().

mcIntegerValue mcRationalValue::GetDen  )  const [inline]
 

Definition at line 594 of file Value.h.

Referenced by isInteger(), and mcNumberHelpers::math_GetNumDen().

double mcRationalValue::GetDouble  )  const [inline]
 

Definition at line 615 of file Value.h.

Referenced by GetLong().

int mcRationalValue::GetFractionalDigitCount int  digits = mcVALUE_DEFAULTPRECISION  )  const
 

Returns the number of fractional digits.

Definition at line 199 of file Value.cpp.

References mcRealValue::isInteger().

Referenced by MakeInteger().

mcRationalValue mcRationalValue::GetFractionalPart  )  const
 

Returns the fractional part of this number, removing the integer one.

This function just subtracts the denominator from the numerator while the numerator is less than the denominator:

5/3 = 1.66666666666 ... . 2/3 = 0.66666666666 ... 19/13 = 1,461538461538461 . 6/13 = 0,461538461538461

mcIntegerValue mcRationalValue::GetIntegerPart  )  const
 

Returns the integer part of this number, removing the fractional one.

This function just subtracts to this number the value returned by GetFractionalPart().

long mcRationalValue::GetLong  )  const [inline, virtual]
 

Implements mcValue.

Definition at line 616 of file Value.h.

References GetDouble().

mcIntegerValue mcRationalValue::GetNum  )  const [inline]
 

Definition at line 596 of file Value.h.

Referenced by mcNumberHelpers::math_GetNumDen().

wxString mcRationalValue::GetStr  )  const [virtual]
 

See mcValue::GetStr.

Implements mcValue.

Definition at line 181 of file Value.cpp.

References mcRealValue::GetStr().

bool mcRationalValue::isInteger  )  const [inline, virtual]
 

Returns TRUE if the denominator of this number is 1.

Implements mcValue.

Definition at line 622 of file Value.h.

References GetDen().

Referenced by MakeInteger().

mcIntegerValue mcRationalValue::MakeInteger int  digits = mcVALUE_DEFAULTPRECISION  )  const
 

Transform a copy of this number multiplying it by 10^GetFractionalDigitCount(*this), thus transforming it into an integer number.

Definition at line 222 of file Value.cpp.

References mcRealValue::floor(), GetFractionalDigitCount(), isInteger(), mcRealValue::isInteger(), mcASSERT, and mcRealValue::pow().

mcRationalValue::mcVALUE_DEFINE_CONSTRUCTORS mcRationalValue  ,
mcMPQ 
 

mcRationalValue::mcVALUE_DEFINE_COW mcMPQ  ,
mpq 
[private]
 

mcRationalValue::mcVALUE_DEFINE_MISCELLANEOUS mcRationalValue  ,
mpq 
 

mcRationalValue::mcVALUE_DEFINE_SETGET_FLAGS  ) 
 

void mcRationalValue::SetDouble double  n  )  [inline]
 

Definition at line 611 of file Value.h.

void mcRationalValue::SetLong long  n  )  [inline, virtual]
 

Implements mcValue.

Definition at line 610 of file Value.h.

void mcRationalValue::SetStr const wxString &  str,
int  base = 10
[inline, virtual]
 

Implements mcValue.

Definition at line 612 of file Value.h.

References WX2GMP.


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

Documentation generated with Doxygen on Sun Feb 6 17:13:09 2005
Visit MathStudio home page for more info

[ Top ]