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

Math
[Global data and functions]


Detailed Description

Global mathematical constants and functions.

#include <qgarlib/math.H>

Constants are defined as static members of class qgar::Math. They include:

Global functions include:


Classes

class  qgar::Math
 Global constants and thresholds, implemented as static data members of the class. More...

Global functions to test approximate equality between numbers

bool qgar::qgEq0 (double aDouble, double anEpsilon=Math::epsilonD())
 Is a double number approximately equal to zero?
bool qgar::qgEq0 (float aFloat, float anEpsilon=Math::epsilonF())
 Is a float number approximately equal to zero?
bool qgar::qgEq0 (int anInt, int anEpsilon=Math::epsilonI())
 Is an integer number approximately equal to zero?
bool qgar::qgEq0Radian (double aRadian, double anEpsilon=Math::epsilonRadian())
 Is an angle in radians approximately equal to zero?
bool qgar::qgEq0Degree (double aDegree, double anEpsilon=Math::epsilonDegree())
 Is an angle in degrees approximately equal to zero?
bool qgar::qgEq (double aDouble1, double aDouble2, double anEpsilon=Math::epsilonD())
 Approximate equality between two double numbers.
bool qgar::qgEq (float aFloat1, float aFloat2, float anEpsilon=Math::epsilonF())
 Approximate equality between two float numbers.
bool qgar::qgEq (int anInt1, int anInt2, int anEpsilon=Math::epsilonI())
 Approximate equality between two integer numbers.
bool qgar::qgEqRadian (double aRadian1, double aRadian2, double anEpsilon=Math::epsilonRadian())
 Approximate equality between two angles in radians.
bool qgar::qgEqDegree (double aDegree1, double aDegree2, double anEpsilon=Math::epsilonDegree())
 Approximate equality between two angles in degrees.

Global functions to test approximate inequality between numbers

bool qgar::qgNotEq0 (double aDouble, double anEpsilon=Math::epsilonD())
 Is a double number approximately not equal to zero?
bool qgar::qgNotEq0 (float aFloat, float anEpsilon=Math::epsilonF())
 Is a float number approximately not equal to zero?
bool qgar::qgNotEq (int anInt, int anEpsilon=Math::epsilonI())
 Is an integer number approximately not equal to zero?
bool qgar::qgNotEq0Radian (double aRadian, double anEpsilon=Math::epsilonRadian())
 Is an angle in radians approximately not equal to zero?
bool qgar::qgNotEq0Degree (double aDegree, double anEpsilon=Math::epsilonDegree())
 Is an angle in degrees approximately not equal to zero?
bool qgar::qgNotEq (double aDouble1, double aDouble2, double anEpsilon=Math::epsilonD())
 Approximate inequality between two double numbers.
bool qgar::qgNotEq (float aFloat1, float aFloat2, float anEpsilon=Math::epsilonF())
 Approximate inequality between two float numbers.
bool qgar::qgNotEq (int anInt1, int anInt2, int anEpsilon=Math::epsilonI())
 Approximate inequality between two integer numbers.
bool qgar::qgNotEqRadian (double aRadian1, double aRadian2, double anEpsilon=Math::epsilonRadian())
 Approximate inequality between two angles in radians.
bool qgar::qgNotEqDegree (double aDegree1, double aDegree2, double anEpsilon=Math::epsilonDegree())
 Approximate inequality between two angles in degrees.

Global functions for conversion in radians and degrees

double qgar::qgRadiansToDegrees (double aRadians)
 Convert from radians to degrees.
double qgar::qgDegreesToRadians (double aDegrees)
 Convert from degrees to radians.

Global error functions

double qgar::qgErf (double x)
 Compute the error function of the argument.
double qgar::qgErfc (double x)
 Compute the complementary error function of the argument.

Global functions to compute the module of a number

template<class T>
qgar::qgAbs (T aVal)
 Module of given value (any type).
template<>
int qgar::qgAbs< int > (int aNb)
 Module of an int number.
template<>
float qgar::qgAbs< float > (float aNb)
 Module of a float number.
template<>
double qgar::qgAbs< double > (double aNb)
 Module of a double number.


Function Documentation

template<class T>
T qgar::qgAbs aVal  )  [inline]
 

Module of given value (any type).

Parameters:
aVal a value

Definition at line 1185 of file math.H.

Referenced by qgar::GenSegment< T >::rho().

template<>
double qgar::qgAbs< double > double  aNb  )  [inline]
 

Module of a double number.

Parameters:
aNb a double double

template<>
float qgar::qgAbs< float > float  aNb  )  [inline]
 

Module of a float number.

Parameters:
aNb a float number

template<>
int qgar::qgAbs< int > int  aNb  )  [inline]
 

Module of an int number.

Parameters:
aNb an int number

double qgar::qgDegreesToRadians double  aDegrees  )  [inline]
 

Convert from degrees to radians.

Parameters:
aDegrees an angle in degrees

Definition at line 1075 of file math.H.

References qgar::Math::QG_DEGREES_TO_RADIANS.

Referenced by qgar::DxfFile::retrievePQgarArc().

bool qgar::qgEq int  anInt1,
int  anInt2,
int  anEpsilon = Math::epsilonI()
[inline]
 

Approximate equality between two integer numbers.

Parameters:
anInt1 an integer number
anInt2 an integer number
anEpsilon tolerance threshold for equality (default qgar::Math::epsilonI())

Definition at line 817 of file math.H.

References qgar::qgEq0().

bool qgar::qgEq float  aFloat1,
float  aFloat2,
float  anEpsilon = Math::epsilonF()
[inline]
 

Approximate equality between two float numbers.

Parameters:
aFloat1 a float number
aFloat2 a float number
anEpsilon tolerance threshold for equality (default qgar::Math::epsilonF())

Definition at line 798 of file math.H.

References qgar::qgEq0().

bool qgar::qgEq double  aDouble1,
double  aDouble2,
double  anEpsilon = Math::epsilonD()
[inline]
 

Approximate equality between two double numbers.

Parameters:
aDouble1 a double number
aDouble2 a double number
anEpsilon tolerance threshold for equality (default qgar::Math::epsilonD())

Definition at line 779 of file math.H.

References qgar::qgEq0().

Referenced by qgar::qgIntersect(), qgar::qgNotEq(), qgar::qgNotEqDegree(), and qgar::qgNotEqRadian().

bool qgar::qgEq0 int  anInt,
int  anEpsilon = Math::epsilonI()
[inline]
 

Is an integer number approximately equal to zero?

Parameters:
anInt an integer number
anEpsilon tolerance threshold aroud zero (optional) (default qgar::Math::epsilonI())

Definition at line 729 of file math.H.

bool qgar::qgEq0 float  aFloat,
float  anEpsilon = Math::epsilonF()
[inline]
 

Is a float number approximately equal to zero?

Parameters:
aFloat a float number
anEpsilon tolerance threshold aroud zero (default qgar::Math::epsilonF())

Definition at line 713 of file math.H.

bool qgar::qgEq0 double  aDouble,
double  anEpsilon = Math::epsilonD()
[inline]
 

Is a double number approximately equal to zero?

Parameters:
aDouble a double number
anEpsilon tolerance threshold aroud zero (default qgar::Math::epsilonD())

Definition at line 697 of file math.H.

Referenced by qgar::GenKMeans< T >::PRIVATEinitCenters(), qgar::qgCircleCenter(), qgar::qgEq(), qgar::qgEq0Degree(), qgar::qgEq0Radian(), qgar::qgEqDegree(), qgar::qgEqRadian(), qgar::qgNotEq(), qgar::qgNotEq0(), qgar::qgNotEq0Degree(), and qgar::qgNotEq0Radian().

bool qgar::qgEq0Degree double  aDegree,
double  anEpsilon = Math::epsilonDegree()
[inline]
 

Is an angle in degrees approximately equal to zero?

Parameters:
aDegree an angle in degrees
anEpsilon tolerance threshold aroud zero (default qgar::Math::epsilonDegree())

Definition at line 762 of file math.H.

References qgar::qgEq0().

bool qgar::qgEq0Radian double  aRadian,
double  anEpsilon = Math::epsilonRadian()
[inline]
 

Is an angle in radians approximately equal to zero?

Parameters:
aRadian an angle in radians
anEpsilon tolerance threshold aroud zero (default qgar::Math::epsilonRadian())

Definition at line 745 of file math.H.

References qgar::qgEq0().

bool qgar::qgEqDegree double  aDegree1,
double  aDegree2,
double  anEpsilon = Math::epsilonDegree()
[inline]
 

Approximate equality between two angles in degrees.

Parameters:
aDegree1 an angle in degrees
aDegree2 an angle in degrees
anEpsilon tolerance threshold for equality (default qgar::Math::epsilonDegree())

Definition at line 853 of file math.H.

References qgar::qgEq0().

bool qgar::qgEqRadian double  aRadian1,
double  aRadian2,
double  anEpsilon = Math::epsilonRadian()
[inline]
 

Approximate equality between two angles in radians.

Parameters:
aRadian1 an angle in radians
aRadian2 an angle in radians
anEpsilon tolerance threshold for equality (default qgar::Math::epsilonRadian())

Definition at line 834 of file math.H.

References qgar::qgEq0().

double qgar::qgErf double  x  ) 
 

Compute the error function of the argument.

Same as C function erf(x) (from <cmath>), which is not yet included in the ISO C standard.

The relative error between the results provided by this function and C function erf(x) is guaranteed to be less than 1.e-11, using the standard precision rate given by function qgar::Math::relError. This precision rate may be changed using function qgar::Math::setRelError. Note that, assuming a usual 52-bit mantissa in a double number, the lowest rate should be 1.e-15

\[ -1~~\leq ~~erf(x) = 1 - erfc(x) = \frac{2}{\sqrt{\pi}} \int_{0}^{x} e^{-t^2} dt ~~\leq~~1 \]

For $\mid{x}\mid\leq 2.2$ , the integral is calculated using a series:

\[ x - \frac{x^3}{3} + \frac{x^5}{5 \times 2!} - \frac{x^7}{7 \times 3!} + ... \]

Parameters:
x a double number

Definition at line 307 of file math.C.

References qgar::Math::QG_2_SQRT_PI, qgar::qgErfc(), and qgar::Math::relError().

Referenced by qgar::qgErfc().

double qgar::qgErfc double  x  ) 
 

Compute the complementary error function of the argument.

Same as C function erfc(x) (from <cmath>), which is not yet included in the ISO C standard.

The relative error between the results provided by this function and C function erfc(x) is guaranteed to be less than 1.e-11, using the standard precision rate given by function qgar::Math::relError. This precision rate may be changed using function qgar::Math::setRelError. Note that, assuming a usual 52-bit mantissa in a double number, the lowest rate should be 1.e-15

\[ 0~~\leq ~~erfc(x) = 1 - erf(x) = \frac{2}{\sqrt{\pi}} \int_{x}^{+\infty} e^{-t^2} dt ~~\leq~~2 \]

For $x > 2.2$ , $erfc(x)$ is calculated using a continued fraction:

\[ \frac{e^{-x^2}}{\sqrt{\pi}}\times \frac{1}{x + U_0} ~~~with~~U_i = \frac{2 + \frac{i}{2}}{x + U_{i+1}} \]

Parameters:
x a double number

Definition at line 351 of file math.C.

References qgar::Math::QG_1_SQRT_PI, qgar::qgErf(), and qgar::Math::relError().

Referenced by qgar::MASK1DGAUSS_phi0(), and qgar::qgErf().

bool qgar::qgNotEq int  anInt1,
int  anInt2,
int  anEpsilon = Math::epsilonI()
[inline]
 

Approximate inequality between two integer numbers.

Parameters:
anInt1 an integer number
anInt2 an integer number
anEpsilon tolerance threshold for inequality (default qgar::Math::epsilonI())

Definition at line 998 of file math.H.

References qgar::qgEq().

bool qgar::qgNotEq float  aFloat1,
float  aFloat2,
float  anEpsilon = Math::epsilonF()
[inline]
 

Approximate inequality between two float numbers.

Parameters:
aFloat1 a float number
aFloat2 a float number
anEpsilon tolerance threshold for inequality (default qgar::Math::epsilonF())

Definition at line 979 of file math.H.

References qgar::qgEq().

bool qgar::qgNotEq double  aDouble1,
double  aDouble2,
double  anEpsilon = Math::epsilonD()
[inline]
 

Approximate inequality between two double numbers.

Parameters:
aDouble1 a double (number)
aDouble2 a double (number)
anEpsilon tolerance threshold for inequality (default qgar::Math::epsilonD())

Definition at line 960 of file math.H.

References qgar::qgEq().

bool qgar::qgNotEq int  anInt,
int  anEpsilon = Math::epsilonI()
[inline]
 

Is an integer number approximately not equal to zero?

Parameters:
anInt an integer number
anEpsilon tolerance threshold aroud zero (default qgar::Math::epsilonI())

Definition at line 909 of file math.H.

References qgar::qgEq0().

bool qgar::qgNotEq0 float  aFloat,
float  anEpsilon = Math::epsilonF()
[inline]
 

Is a float number approximately not equal to zero?

Parameters:
aFloat a float number
anEpsilon tolerance threshold aroud zero (default qgar::Math::epsilonF())

Definition at line 893 of file math.H.

References qgar::qgEq0().

bool qgar::qgNotEq0 double  aDouble,
double  anEpsilon = Math::epsilonD()
[inline]
 

Is a double number approximately not equal to zero?

Parameters:
aDouble a double (number)
anEpsilon tolerance threshold aroud zero (default qgar::Math::epsilonD())

Definition at line 877 of file math.H.

References qgar::qgEq0().

bool qgar::qgNotEq0Degree double  aDegree,
double  anEpsilon = Math::epsilonDegree()
[inline]
 

Is an angle in degrees approximately not equal to zero?

Parameters:
aDegree an angle in degrees
anEpsilon tolerance threshold aroud zero (default qgar::Math::qgEDegree())

Definition at line 942 of file math.H.

References qgar::qgEq0().

bool qgar::qgNotEq0Radian double  aRadian,
double  anEpsilon = Math::epsilonRadian()
[inline]
 

Is an angle in radians approximately not equal to zero?

Parameters:
aRadian an angle in radians
anEpsilon tolerance threshold aroud zero (default qgar::Math::epsilonRadian())

Definition at line 925 of file math.H.

References qgar::qgEq0().

bool qgar::qgNotEqDegree double  aDegree1,
double  aDegree2,
double  anEpsilon = Math::epsilonDegree()
[inline]
 

Approximate inequality between two angles in degrees.

Parameters:
aDegree1 an angle in degrees
aDegree2 an angle in degrees
anEpsilon tolerance threshold for inequality (default Math::epsilonDegree())

Definition at line 1035 of file math.H.

References qgar::qgEq().

bool qgar::qgNotEqRadian double  aRadian1,
double  aRadian2,
double  anEpsilon = Math::epsilonRadian()
[inline]
 

Approximate inequality between two angles in radians.

Parameters:
aRadian1 an angle in radians
aRadian2 an angle in radians
anEpsilon tolerance threshold for inequality (default qgar::Math::epsilonRadian())

Definition at line 1016 of file math.H.

References qgar::qgEq().

double qgar::qgRadiansToDegrees double  aRadians  )  [inline]
 

Convert from radians to degrees.

Parameters:
aRadians an angle in radians

Definition at line 1062 of file math.H.

References qgar::Math::QG_RADIANS_TO_DEGREES.

Referenced by qgar::GenSegment< T >::angleDegrees(), qgar::GenArc< T >::angleDegrees(), qgar::qgAngleDegrees(), qgar::qgSlopeDegrees(), qgar::GenSegment< T >::slopeDegrees(), qgar::GenArc< T >::sourceAngleDegrees(), qgar::GenArc< T >::targetAngleDegrees(), and qgar::GenSegment< T >::thetaDegrees().