Jpp
Classes | Functions | Variables
JMATH Namespace Reference

Auxiliary classes and methods for mathematical operations. More...

Classes

struct  JCalculator
 Auxiliary class for arithmetic operations on objects. More...
 
class  JGauss
 Data structure for Gaussian function on top of a flat background. More...
 
struct  JLimits
 Auxiliary class for minimum and maximum values for any class. More...
 
struct  JLimits< T, false >
 Template spacialisation of JMATH::JRandom for other data types. More...
 
struct  JLimits< T, true >
 Template spacialisation of JMATH::JLimits for numerical values. More...
 
struct  JMath
 Auxiliary base class for aritmetic operations of derived class types. More...
 
struct  JMath< T, JNullType >
 Template class for data structures with arithmetic capabilities. More...
 
class  JMatrix1D
 1 x 1 matrix More...
 
class  JMatrix1S
 1 x 1 symmetric matrix More...
 
class  JMatrix2D
 2 x 2 matrix More...
 
class  JMatrix2S
 2 x 2 symmetric matrix More...
 
class  JMatrix3D
 3 x 3 matrix More...
 
class  JMatrix3S
 3 x 3 symmetric matrix More...
 
class  JMatrix4D
 4 x 4 matrix More...
 
class  JMatrix4S
 4 x 4 symmetric matrix More...
 
class  JMatrix5D
 5 x 5 matrix More...
 
class  JMatrix5S
 5 x 5 symmetric matrix More...
 
struct  JMatrixND
 NxN matrix. More...
 
struct  JMatrixND_t
 Basic NxN matrix. More...
 
struct  JMatrixNS
 N x N symmetric matrix. More...
 
struct  JNumber
 Simple wrapper around template data type to ensure that zero is the default value. More...
 
class  JPolynome
 Polynome function object. More...
 
class  JPower
 Power law function object. More...
 
struct  JRandom
 Template definition of random value generator. More...
 
struct  JRandom< T, false >
 Template spacialisation of JMATH::JRandom for non-numerical data types. More...
 
struct  JRandom< T, true >
 Template spacialisation of JMATH::JRandom for numerical values. More...
 
class  JTrigonometric
 Trigonometric function object for sin and cos. More...
 
struct  JVectorND
 Nx1 matrix. More...
 
struct  JZero
 Auxiliary class to assign zero value. More...
 

Functions

template<class T >
const JCalculator< T, 1 > & operator* (const T &first, const T &second)
 Product evaluation of objects. More...
 
template<class T , int N>
const JCalculator< T, N+1 > & operator* (const T &first, const JCalculator< T, N > &second)
 Recursive product evaluation of objects. More...
 
template<class T , int N>
const JCalculator< T, N+1 > & operator* (const JCalculator< T, N > &first, const T &second)
 Recursive product evaluation of objects. More...
 
void randomize (JMatrix1S *p)
 Randomize matrix. More...
 
void randomize (JMatrix2S *p)
 Randomize matrix. More...
 
void randomize (JMatrix3S *p)
 Randomize matrix. More...
 
void randomize (JMatrix4S *p)
 Randomize matrix. More...
 
void randomize (JMatrix5S *p)
 Randomize matrix. More...
 
long long int factorial (const long long int n)
 Determine factorial. More...
 
long long int factorial (const long long int n, const long long int m)
 Determine combinatorics. More...
 
template<class JFirst_t , class JSecond_t >
bool equals (const JFirst_t &first, const JSecond_t &second, const double precision=std::numeric_limits< double >::min())
 Check equality. More...
 
template<class JFirst_t , class JSecond_t >
double getDistanceSquared (const JFirst_t &first, const JSecond_t &second)
 Get square of distance between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getDistance (const JFirst_t &first, const JSecond_t &second)
 Get distance between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getDot (const JFirst_t &first, const JSecond_t &second)
 Get dot product of objects. More...
 
template<class JFirst_t , class JSecond_t >
double getAngle (const JFirst_t &first, const JSecond_t &second)
 Get space angle between objects. More...
 
template<class JFirst_t , class JSecond_t >
double getPerpDot (const JFirst_t &first, const JSecond_t &second)
 Get perpendicular dot product of objects. More...
 
template<class T >
interpolate (const T &first, const T &second, const double alpha)
 Interpolation between objects. More...
 
template<class T >
getRandom ()
 Get random value. More...
 
template<class T >
getRandom (const T min, const T max)
 Get uniformly distributed random value between given limits. More...
 
template<class T >
getRandom (const T min, const T max, const T precision)
 Get uniformly distributed random value between given limits. More...
 
template<>
double getRandom (const double min, const double max, const double precision)
 Template specialisation for data type double. More...
 
template<class T >
getZero ()
 Get zero value for a given data type. More...
 
template<>
float getZero< float > ()
 Get zero value for float. More...
 
template<>
double getZero< double > ()
 Get zero value for double. More...
 
template<>
long double getZero< long double > ()
 Get zero value for long double. More...
 

Variables

static const JZero zero
 Function object to assign zero value. More...
 

Detailed Description

Auxiliary classes and methods for mathematical operations.

Author
mdejong

Function Documentation

◆ operator*() [1/3]

template<class T >
const JCalculator<T, 1>& JMATH::operator* ( const T &  first,
const T &  second 
)
inline

Product evaluation of objects.

Multiply objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 53 of file JCalculator.hh.

54  {
55  JCalculator<T, 1>::calculator.mul(first, second);
56 
58  }

◆ operator*() [2/3]

template<class T , int N>
const JCalculator<T, N+1>& JMATH::operator* ( const T &  first,
const JCalculator< T, N > &  second 
)
inline

Recursive product evaluation of objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 69 of file JCalculator.hh.

70  {
71  JCalculator<T, N+1>::calculator.mul(first, second);
72 
74  }

◆ operator*() [3/3]

template<class T , int N>
const JCalculator<T, N+1>& JMATH::operator* ( const JCalculator< T, N > &  first,
const T &  second 
)
inline

Recursive product evaluation of objects.

Parameters
firstfirst object
secondsecond object
Returns
calculator

Definition at line 85 of file JCalculator.hh.

86  {
87  JCalculator<T, N+1>::calculator.mul(first, second);
88 
90  }

◆ randomize() [1/5]

void JMATH::randomize ( JMatrix1S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 29 of file JMathTestkit.hh.

30  {
31  new (p) JMatrix1S(getRandom<double>(-1.0, +1.0));
32  }

◆ randomize() [2/5]

void JMATH::randomize ( JMatrix2S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 40 of file JMathTestkit.hh.

41  {
42  new (p) JMatrix2S(getRandom<double>(-1.0,+1.0),
43  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0));
44 
45  p->a01 = p->a10;
46  }

◆ randomize() [3/5]

void JMATH::randomize ( JMatrix3S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 54 of file JMathTestkit.hh.

55  {
56  new (p) JMatrix3S(getRandom<double>(-1.0,+1.0),
57  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
58  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0));
59 
60  p->a01 = p->a10;
61  p->a02 = p->a20;
62  p->a12 = p->a21;
63  }

◆ randomize() [4/5]

void JMATH::randomize ( JMatrix4S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 71 of file JMathTestkit.hh.

72  {
73  new (p) JMatrix4S(getRandom<double>(-1.0,+1.0),
74  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
75  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
76  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0));
77 
78  p->a01 = p->a10;
79  p->a02 = p->a20;
80  p->a03 = p->a30;
81  p->a12 = p->a21;
82  p->a13 = p->a31;
83  p->a23 = p->a32;
84  }

◆ randomize() [5/5]

void JMATH::randomize ( JMatrix5S p)
inline

Randomize matrix.

Parameters
ppointer to valid object

Definition at line 92 of file JMathTestkit.hh.

93  {
94  new (p) JMatrix5S(getRandom<double>(-1.0,+1.0),
95  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
96  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
97  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0),
98  getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0), getRandom<double>(-1.0,+1.0));
99 
100  p->a01 = p->a10;
101  p->a02 = p->a20;
102  p->a03 = p->a30;
103  p->a04 = p->a40;
104  p->a12 = p->a21;
105  p->a13 = p->a31;
106  p->a14 = p->a41;
107  p->a23 = p->a32;
108  p->a24 = p->a42;
109  p->a34 = p->a43;
110  }

◆ factorial() [1/2]

long long int JMATH::factorial ( const long long int  n)
inline

Determine factorial.

Parameters
nnumber
Returns
factorial (= n!)

Definition at line 41 of file JMathToolkit.hh.

42  {
43  if (n < 0) {
44  THROW(JValueOutOfRange, "JMATH::factorial(): invalid argument " << n);
45  }
46 
47  if (n != 1)
48  return n * factorial(n - 1);
49  else
50  return 1;
51  }

◆ factorial() [2/2]

long long int JMATH::factorial ( const long long int  n,
const long long int  m 
)
inline

Determine combinatorics.

Parameters
nnumber
mnumber
Returns
n!/(m!*(n-m)!)

Definition at line 61 of file JMathToolkit.hh.

62  {
63  if (n < 0 || m < 0 || n < m) {
64  THROW(JValueOutOfRange, "JMATH::factorial(): invalid argument " << n << ' ' << m);
65  }
66 
67  if (n == m)
68  return 1;
69  else if (m == 0)
70  return 1;
71  else
72  return factorial(n - 1, m - 1) + factorial(n - 1, m);
73  }

◆ equals()

template<class JFirst_t , class JSecond_t >
bool JMATH::equals ( const JFirst_t &  first,
const JSecond_t &  second,
const double  precision = std::numeric_limits<double>::min() 
)
inline

Check equality.

Parameters
firstfirst object
secondsecond object
precisionprecision
Returns
true if two objects are equals; else false

Definition at line 85 of file JMathToolkit.hh.

88  {
89  return first.equals(second, precision);
90  }

◆ getDistanceSquared()

template<class JFirst_t , class JSecond_t >
double JMATH::getDistanceSquared ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get square of distance between objects.

Parameters
firstfirst object
secondsecond object
Returns
square of distance

Definition at line 101 of file JMathToolkit.hh.

103  {
104  return first.getDistanceSquared(second);
105  }

◆ getDistance()

template<class JFirst_t , class JSecond_t >
double JMATH::getDistance ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get distance between objects.

Parameters
firstfirst object
secondsecond object
Returns
distance

Definition at line 116 of file JMathToolkit.hh.

118  {
119  return first.getDistance(second);
120  }

◆ getDot()

template<class JFirst_t , class JSecond_t >
double JMATH::getDot ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get dot product of objects.

Parameters
firstfirst object
secondsecond object
Returns
dot product

Definition at line 131 of file JMathToolkit.hh.

133  {
134  return first.getDot(second);
135  }

◆ getAngle()

template<class JFirst_t , class JSecond_t >
double JMATH::getAngle ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get space angle between objects.

Parameters
firstfirst object
secondsecond object
Returns
angle [deg]

Definition at line 146 of file JMathToolkit.hh.

148  {
149  const double dot = getDot(first,second);
150 
151  if (dot >= +1.0)
152  return 0.0;
153  else if (dot <= -1.0)
154  return 180.0;
155  else
156  return acos(dot) * 180.0 / acos(-1.0);
157  }

◆ getPerpDot()

template<class JFirst_t , class JSecond_t >
double JMATH::getPerpDot ( const JFirst_t &  first,
const JSecond_t &  second 
)
inline

Get perpendicular dot product of objects.

Parameters
firstfirst object
secondsecond object
Returns
perpendicular dot product

Definition at line 168 of file JMathToolkit.hh.

170  {
171  return first.getPerpDot(second);
172  }

◆ interpolate()

template<class T >
T JMATH::interpolate ( const T &  first,
const T &  second,
const double  alpha 
)
inline

Interpolation between objects.

The result is equal to result = (1 - alpha) x (first) + (alpha) x (second).

Parameters
firstfirst object
secondsecond object
alphainterpolation factor (normally between 0 and 1)
Returns
result

Definition at line 185 of file JMathToolkit.hh.

188  {
189  return T(first).interpolate(second, alpha);
190  }

◆ getRandom() [1/4]

template<class T >
T JMATH::getRandom ( )
inline

Get random value.

Returns
random value

Definition at line 113 of file JRandom.hh.

114  {
115  return JRandom<T>::getRandom();
116  }

◆ getRandom() [2/4]

template<class T >
T JMATH::getRandom ( const T  min,
const T  max 
)
inline

Get uniformly distributed random value between given limits.

Parameters
minminimal value
maxmaximal value
Returns
random value

Definition at line 127 of file JRandom.hh.

129  {
130  return JRandom<T, true>::getRandom(min, max);
131  }

◆ getRandom() [3/4]

template<class T >
T JMATH::getRandom ( const T  min,
const T  max,
const T  precision 
)
inline

Get uniformly distributed random value between given limits.

Parameters
minminimal value
maxmaximal value
precisionprecision
Returns
random value

Definition at line 143 of file JRandom.hh.

146  {
147  return JRandom<T, true>::getRandom(min, max);
148  }

◆ getRandom() [4/4]

template<>
double JMATH::getRandom ( const double  min,
const double  max,
const double  precision 
)
inline

Template specialisation for data type double.

Definition at line 155 of file JRandom.hh.

158  {
159  double value = getRandom<double>(min, max);
160 
161  if (precision != 0.0) {
162 
163  const long long int ip = (long long int) (1.0 / precision);
164 
165  value = ((double) ((long long int) (value * ip))) / ip;
166  }
167 
168  return value;
169  }

◆ getZero()

template<class T >
T JMATH::getZero ( )
inline

Get zero value for a given data type.

The default implementation of this method returns an object which is created with the default constructor. This method should be specialised if this value does not correspond to the equivalent of a zero result.

Returns
zero

Definition at line 26 of file JZero.hh.

27  {
28  return T();
29  }

◆ getZero< float >()

template<>
float JMATH::getZero< float > ( )
inline

Get zero value for float.

Returns
zero

Definition at line 37 of file JZero.hh.

38  {
39  return float(0.0);
40  }

◆ getZero< double >()

template<>
double JMATH::getZero< double > ( )
inline

Get zero value for double.

Returns
zero

Definition at line 49 of file JZero.hh.

50  {
51  return double(0.0);
52  }

◆ getZero< long double >()

template<>
long double JMATH::getZero< long double > ( )
inline

Get zero value for long double.

Returns
zero

Definition at line 61 of file JZero.hh.

62  {
63  return (long double)(0.0);
64  }

Variable Documentation

◆ zero

const JZero JMATH::zero
static

Function object to assign zero value.

Definition at line 94 of file JZero.hh.

JMATH::JMatrix2S
2 x 2 symmetric matrix
Definition: JMatrix2S.hh:26
JMATH::JMatrix5D::a31
double a31
Definition: JMatrix5D.hh:525
JMATH::JMatrix3D::a01
double a01
Definition: JMath/JMatrix3D.hh:385
JMATH::JMatrix5D::a04
double a04
Definition: JMatrix5D.hh:522
JMATH::JMatrix3D::a21
double a21
Definition: JMath/JMatrix3D.hh:387
JMATH::JMatrix5D::a21
double a21
Definition: JMatrix5D.hh:524
JMATH::JMatrix4D::a02
double a02
Definition: JMatrix4D.hh:438
JMATH::JMatrix3S
3 x 3 symmetric matrix
Definition: JMatrix3S.hh:26
JMATH::JMatrix5D::a32
double a32
Definition: JMatrix5D.hh:525
JMATH::JMatrix5D::a20
double a20
Definition: JMatrix5D.hh:524
JMATH::JMatrix5D::a30
double a30
Definition: JMatrix5D.hh:525
JMATH::JMatrix3D::a20
double a20
Definition: JMath/JMatrix3D.hh:387
JMATH::JMatrix5D::a01
double a01
Definition: JMatrix5D.hh:522
JMATH::JMatrix5D::a34
double a34
Definition: JMatrix5D.hh:525
JMATH::JMatrix4D::a23
double a23
Definition: JMatrix4D.hh:440
JTOOLS::n
const int n
Definition: JPolint.hh:628
JMATH::JMatrix4D::a30
double a30
Definition: JMatrix4D.hh:441
JMATH::JMatrix2D::a10
double a10
Definition: JMath/JMatrix2D.hh:347
JMATH::JMatrix2D::a01
double a01
Definition: JMath/JMatrix2D.hh:346
JMATH::JMatrix5D::a13
double a13
Definition: JMatrix5D.hh:523
JMATH::JMatrix4D::a20
double a20
Definition: JMatrix4D.hh:440
JMATH::JMatrix5D::a12
double a12
Definition: JMatrix5D.hh:523
JMATH::JMatrix5D::a41
double a41
Definition: JMatrix5D.hh:526
JMATH::JMatrix5D::a02
double a02
Definition: JMatrix5D.hh:522
JMATH::JMatrix4S
4 x 4 symmetric matrix
Definition: JMatrix4S.hh:26
JMATH::JMatrix5D::a10
double a10
Definition: JMatrix5D.hh:523
JMATH::JMatrix5D::a40
double a40
Definition: JMatrix5D.hh:526
THROW
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
JMATH::JMatrix1S
1 x 1 symmetric matrix
Definition: JMatrix1S.hh:26
JMATH::JMatrix3D::a12
double a12
Definition: JMath/JMatrix3D.hh:386
JMATH::JMatrix4D::a03
double a03
Definition: JMatrix4D.hh:438
JMATH::getRandom
double getRandom(const double min, const double max, const double precision)
Template specialisation for data type double.
Definition: JRandom.hh:155
JMATH::JMatrix4D::a10
double a10
Definition: JMatrix4D.hh:439
JMATH::JMatrix4D::a31
double a31
Definition: JMatrix4D.hh:441
JMATH::JMatrix5D::a03
double a03
Definition: JMatrix5D.hh:522
JMATH::factorial
long long int factorial(const long long int n, const long long int m)
Determine combinatorics.
Definition: JMathToolkit.hh:61
JMATH::JMatrix5D::a42
double a42
Definition: JMatrix5D.hh:526
JMATH::JMatrix4D::a32
double a32
Definition: JMatrix4D.hh:441
JMATH::JMatrix4D::a13
double a13
Definition: JMatrix4D.hh:439
JMATH::JMatrix4D::a21
double a21
Definition: JMatrix4D.hh:440
JMATH::JMatrix4D::a12
double a12
Definition: JMatrix4D.hh:439
JMATH::JMatrix4D::a01
double a01
Definition: JMatrix4D.hh:438
JMATH::JCalculator
Auxiliary class for arithmetic operations on objects.
Definition: JCalculator.hh:18
JMATH::JMatrix3D::a02
double a02
Definition: JMath/JMatrix3D.hh:385
JMATH::JMatrix5D::a23
double a23
Definition: JMatrix5D.hh:524
JMATH::JMatrix5D::a14
double a14
Definition: JMatrix5D.hh:523
JMATH::JMatrix5D::a43
double a43
Definition: JMatrix5D.hh:526
JMATH::JMatrix3D::a10
double a10
Definition: JMath/JMatrix3D.hh:386
JMATH::getDot
double getDot(const JFirst_t &first, const JSecond_t &second)
Get dot product of objects.
Definition: JMathToolkit.hh:131
JMATH::JMatrix5D::a24
double a24
Definition: JMatrix5D.hh:524
JMATH::JMatrix5S
5 x 5 symmetric matrix
Definition: JMatrix5S.hh:26