SAMRAI::tbox::MathUtilities< TYPE > Class Template Reference

#include <source/toolbox/base/MathUtilities.h>

List of all members.

Public Member Functions

template<>
bool isNaN (const float &value)
template<>
bool isNaN (const double &value)
template<>
bool isNaN (const dcomplex &value)
template<>
bool equalEps (const float &a, const float &b)
template<>
bool equalEps (const double &a, const double &b)
template<>
bool equalEps (const dcomplex &a, const dcomplex &b)
template<>
bool Rand (const bool &low, const bool &width)
template<>
char Rand (const char &low, const char &width)
template<>
int Rand (const int &low, const int &width)
template<>
float Rand (const float &low, const float &width)
template<>
double Rand (const double &low, const double &width)
template<>
dcomplex Rand (const dcomplex &low, const dcomplex &width)
template<>
dcomplex Min (dcomplex a, dcomplex b)
template<>
dcomplex Max (dcomplex a, dcomplex b)
template<>
int Abs (int a)
template<>
float Abs (float a)
template<>
double Abs (double a)
template<>
float round (float a)
template<>
double round (double a)
template<>
bool s_zero
template<>
bool s_one
template<>
bool s_signaling_nan
template<>
bool s_max
template<>
bool s_min
template<>
bool s_epsilon
template<>
char s_zero
template<>
char s_one
template<>
char s_signaling_nan
template<>
char s_max
template<>
char s_min
template<>
char s_epsilon
template<>
int s_zero
template<>
int s_one
template<>
int s_signaling_nan
template<>
int s_max
template<>
int s_min
template<>
int s_epsilon
template<>
float s_zero
template<>
float s_one
template<>
float s_signaling_nan
template<>
float s_max
template<>
float s_min
template<>
float s_epsilon
template<>
double s_zero
template<>
double s_one
template<>
double s_signaling_nan
template<>
double s_max
template<>
double s_min
template<>
double s_epsilon
template<>
dcomplex s_zero
template<>
dcomplex s_one
template<>
dcomplex s_signaling_nan
template<>
dcomplex s_max
template<>
dcomplex s_min
template<>
dcomplex s_epsilon
template<>
bool isNaN (const float &value)
template<>
bool isNaN (const double &value)
template<>
bool isNaN (const dcomplex &value)
template<>
bool equalEps (const float &a, const float &b)
template<>
bool equalEps (const double &a, const double &b)
template<>
bool equalEps (const dcomplex &a, const dcomplex &b)
template<>
dcomplex Min (dcomplex a, dcomplex b)
template<>
dcomplex Max (dcomplex a, dcomplex b)
template<>
int Abs (int a)
template<>
float Abs (float a)
template<>
double Abs (double a)
template<>
bool Rand (const bool &low, const bool &width)
template<>
char Rand (const char &low, const char &width)
template<>
int Rand (const int &low, const int &width)
template<>
float Rand (const float &low, const float &width)
template<>
double Rand (const double &low, const double &width)
template<>
dcomplex Rand (const dcomplex &low, const dcomplex &width)
template<>
float round (float x)
template<>
double round (double x)

Static Public Member Functions

static TYPE getZero ()
 Return the value 0 for the template type.
static TYPE getOne ()
 Return the value 1 for the template type.
static TYPE getSignalingNaN ()
 Return the IEEE signaling NaN for the template type on architectures that support it.
static bool isNaN (const TYPE &value)
 Return true if the supplied value is NaN; else, false.
static void setArrayToSignalingNaN (Array< TYPE > &array)
 Set array entries to value given by getSignalingNaN().
static void setArrayToSignalingNaN (TYPE *array, int n=1)
 Set array entries to value given by getSignalingNaN().
static bool equalEps (const TYPE &a, const TYPE &b)
 Return true if given values have a relative difference smaller than sqrt(mach_eps) for the template type.
static TYPE getMax ()
 Return max value for the template type.
static void setArrayToMax (Array< TYPE > &array)
 Set array entries to value given by getMax().
static void setArrayToMax (TYPE *array, int n=1)
 Set array entries to value given by getMax().
static TYPE getMin ()
 Return min value for the template type.
static void setArrayToMin (Array< TYPE > &array)
 Set array entries to value given by getMin().
static void setArrayToMin (TYPE *array, int n=1)
 Set array entries to value given by getMin().
static TYPE getEpsilon ()
 Return epsilon value for the template type.
static void setArrayToEpsilon (Array< TYPE > &array)
 Set array entries to value given by getEpsilon().
static void setArrayToEpsilon (TYPE *array, int n=1)
 Set array entries to value given by getEpsilon().
static TYPE Min (TYPE a, TYPE b)
 Return the minimum value of a and b.
static TYPE Max (TYPE a, TYPE b)
 Return the maximum value of a and b.
static TYPE Abs (TYPE a)
 Return absolute value of a.
static TYPE round (TYPE a)
 Return nearest integral value.
static TYPE Rand (const TYPE &low, const TYPE &width)
 Generate and return a random value from low to low+width.


Detailed Description

template<class TYPE>
class SAMRAI::tbox::MathUtilities< TYPE >

Class MathUtilities is a utility that provides some basic math-related functions and routines for initializing data to signaling NaNs and POSIX constants like INT_MAX, FLT_MAX, DBL_MAX, etc. Signaling NaNs force a trap if they are used in a numerical operation, so they are a useful way to track uninitialized floating point data. For example, setting integer values to INT_MAX is a useful way to track uninitialized integer values.

IMPORTANT: To properly trap operations based on signaling NaN values, the routine IEEE::setupFloatingPointExceptionHandlers() must be called. This is normally done in the SAMRAIManager::startup() routine.

The implementation of this class depends heavily on the particular computer architecture and how it implements floating point arithmetic and hardware traps.

Note that the class

See also:
tbox::IEEE also provides operations for dealing with signaling NaNs. This class provides the actual implementation for such operations with functions in tbox::IEEE calling the approriate operations provided here. The class tbox::IEEE is not templated on the data type and so calling the operations provided there may be easier in some cases, such as in codes built based on earlier versions of SAMRAI.


Member Function Documentation

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::getZero (  )  [inline, static]

Return the value 0 for the template type.

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::getOne (  )  [inline, static]

Return the value 1 for the template type.

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::getSignalingNaN (  )  [inline, static]

Return the IEEE signaling NaN for the template type on architectures that support it.

Using this value in a numerical expression will cause a program abort.

For float, double, and dcomplex types, the usual signaling Nan value will be returned if defined for the architecture and compiler. For char and int types, the POSIX max value for the type is returned. For other template types, zero is returned.

template<class TYPE>
bool SAMRAI::tbox::MathUtilities< TYPE >::isNaN ( const TYPE &  value  )  [inline, static]

Return true if the supplied value is NaN; else, false.

For float and double, will check value against signaling NaN. For dcomplex will return true if either real and imaginary part is signaling NaN and false otherwise. For other types will return false always.

Parameters:
value Value to test

template<class TYPE>
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToSignalingNaN ( Array< TYPE > &  array  )  [static]

Set array entries to value given by getSignalingNaN().

Parameters:
array SAMRAI array to set

template<class TYPE>
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToSignalingNaN ( TYPE *  array,
int  n = 1 
) [static]

Set array entries to value given by getSignalingNaN().

Parameters:
array Pointer to first array entry
n Integer to number of array entries.

template<class TYPE>
bool SAMRAI::tbox::MathUtilities< TYPE >::equalEps ( const TYPE &  a,
const TYPE &  b 
) [inline, static]

Return true if given values have a relative difference smaller than sqrt(mach_eps) for the template type.

Valid for float/double/dcomplex only. For dcomplex will return true if both real and imaginary part values have a relative difference smaller than sqrt(mach_eps).

For non float/double/dcomplex will just return ( a == b ).

Parameters:
a 
b 

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::getMax (  )  [inline, static]

Return max value for the template type.

For boolean type, will return "true". For dcomplex type, will return a dcomplex value with both real and imaginary parts set to the POSIX max value for type double. For other types, will return the POSIX max value for the type.

template<class TYPE>
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMax ( Array< TYPE > &  array  )  [static]

Set array entries to value given by getMax().

Parameters:
array SAMRAI array to set

template<class TYPE>
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMax ( TYPE *  array,
int  n = 1 
) [static]

Set array entries to value given by getMax().

Parameters:
array Pointer to first array entry
n Integer to number of array entries.

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::getMin (  )  [inline, static]

Return min value for the template type.

For boolean type, will return "false". For dcomplex type, will return a dcomplex value with both real and imaginary parts set to the POSIX min value for type double. For other types, will return the POSIX min value for the type.

template<class TYPE>
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMin ( Array< TYPE > &  array  )  [static]

Set array entries to value given by getMin().

Parameters:
array SAMRAI array to set

template<class TYPE>
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMin ( TYPE *  array,
int  n = 1 
) [static]

Set array entries to value given by getMin().

Parameters:
array Pointer to first array entry
n Integer to number of array entries.

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::getEpsilon (  )  [inline, static]

Return epsilon value for the template type.

For boolean type, will return "true". For integer type, will return "1". For dcomplex type, will return a dcomplex value with both real and imaginary parts set to the POSIX epsilon value for type double. For other types, will return the POSIX epsilon value for the type.

template<class TYPE>
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToEpsilon ( Array< TYPE > &  array  )  [static]

Set array entries to value given by getEpsilon().

Parameters:
array SAMRAI array to set

template<class TYPE>
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToEpsilon ( TYPE *  array,
int  n = 1 
) [static]

Set array entries to value given by getEpsilon().

Parameters:
array Pointer to first array entry
n Integer to number of array entries.

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::Min ( TYPE  a,
TYPE  b 
) [inline, static]

Return the minimum value of a and b.

For dcomplex type will return the value with the minimum norm.

Parameters:
a 
b 

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::Max ( TYPE  a,
TYPE  b 
) [inline, static]

Return the maximum value of a and b.

For dcomplex type will return the value with the maximum norm.

Parameters:
a 
b 

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::Abs ( TYPE  a  )  [inline, static]

Return absolute value of a.

For int, float, and double types will return the absolute numerical value. For other types, will return the input value.

Parameters:
a 

template<class TYPE>
TYPE SAMRAI::tbox::MathUtilities< TYPE >::round ( TYPE  a  )  [inline, static]

Return nearest integral value.

If the argument is halfway between two integral values then round away from zero for float and double types. For other types, will return the input value.

Parameters:
a 

template<class TYPE>
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::Rand ( const TYPE &  low,
const TYPE &  width 
) [static]

Generate and return a random value from low to low+width.

For boolean type, value is either "true" or "false" based on value generated by mrand48(). For other types, returned value is computed as width * drand48() + low. When type is char, this value is cast to a char. When type is dcomplex, real and imaginary parts are computed separately this way.

Parameters:
low Starting value for range
width Width of the range.

template<>
bool SAMRAI::tbox::MathUtilities< float >::isNaN ( const float &  value  ) 

template<>
bool SAMRAI::tbox::MathUtilities< double >::isNaN ( const double &  value  ) 

template<>
bool SAMRAI::tbox::MathUtilities< dcomplex >::isNaN ( const dcomplex value  ) 

template<>
bool SAMRAI::tbox::MathUtilities< float >::equalEps ( const float &  a,
const float &  b 
)

template<>
bool SAMRAI::tbox::MathUtilities< double >::equalEps ( const double &  a,
const double &  b 
)

template<>
bool SAMRAI::tbox::MathUtilities< dcomplex >::equalEps ( const dcomplex a,
const dcomplex b 
)

template<>
bool SAMRAI::tbox::MathUtilities< bool >::Rand ( const bool &  low,
const bool &  width 
)

template<>
char SAMRAI::tbox::MathUtilities< char >::Rand ( const char &  low,
const char &  width 
)

template<>
int SAMRAI::tbox::MathUtilities< int >::Rand ( const int &  low,
const int &  width 
)

template<>
float SAMRAI::tbox::MathUtilities< float >::Rand ( const float &  low,
const float &  width 
)

template<>
double SAMRAI::tbox::MathUtilities< double >::Rand ( const double &  low,
const double &  width 
)

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Rand ( const dcomplex low,
const dcomplex width 
)

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Min ( dcomplex  a,
dcomplex  b 
)

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Max ( dcomplex  a,
dcomplex  b 
)

template<>
int SAMRAI::tbox::MathUtilities< int >::Abs ( int  a  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::Abs ( float  a  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::Abs ( double  a  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::round ( float  a  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::round ( double  a  ) 

template<>
bool SAMRAI::tbox::MathUtilities< bool >::s_zero (  ) 

template<>
bool SAMRAI::tbox::MathUtilities< bool >::s_one (  ) 

template<>
bool SAMRAI::tbox::MathUtilities< bool >::s_signaling_nan (  ) 

template<>
bool SAMRAI::tbox::MathUtilities< bool >::s_max (  ) 

template<>
bool SAMRAI::tbox::MathUtilities< bool >::s_min (  ) 

template<>
bool SAMRAI::tbox::MathUtilities< bool >::s_epsilon (  ) 

template<>
char SAMRAI::tbox::MathUtilities< char >::s_zero (  ) 

template<>
char SAMRAI::tbox::MathUtilities< char >::s_one (  ) 

template<>
char SAMRAI::tbox::MathUtilities< char >::s_signaling_nan (  ) 

template<>
char SAMRAI::tbox::MathUtilities< char >::s_max (  ) 

template<>
char SAMRAI::tbox::MathUtilities< char >::s_min (  ) 

template<>
char SAMRAI::tbox::MathUtilities< char >::s_epsilon (  ) 

template<>
int SAMRAI::tbox::MathUtilities< int >::s_zero (  ) 

template<>
int SAMRAI::tbox::MathUtilities< int >::s_one (  ) 

template<>
int SAMRAI::tbox::MathUtilities< int >::s_signaling_nan (  ) 

template<>
int SAMRAI::tbox::MathUtilities< int >::s_max (  ) 

template<>
int SAMRAI::tbox::MathUtilities< int >::s_min (  ) 

template<>
int SAMRAI::tbox::MathUtilities< int >::s_epsilon (  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::s_zero (  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::s_one (  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::s_signaling_nan (  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::s_max (  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::s_min (  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::s_epsilon (  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::s_zero (  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::s_one (  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::s_signaling_nan (  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::s_max (  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::s_min (  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::s_epsilon (  ) 

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_zero (  ) 

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_one (  ) 

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_signaling_nan (  ) 

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_max (  ) 

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_min (  ) 

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_epsilon (  ) 

template<>
bool SAMRAI::tbox::MathUtilities< float >::isNaN ( const float &  value  ) 

template<>
bool SAMRAI::tbox::MathUtilities< double >::isNaN ( const double &  value  ) 

template<>
bool SAMRAI::tbox::MathUtilities< dcomplex >::isNaN ( const dcomplex value  ) 

template<>
bool SAMRAI::tbox::MathUtilities< float >::equalEps ( const float &  a,
const float &  b 
)

template<>
bool SAMRAI::tbox::MathUtilities< double >::equalEps ( const double &  a,
const double &  b 
)

template<>
bool SAMRAI::tbox::MathUtilities< dcomplex >::equalEps ( const dcomplex a,
const dcomplex b 
)

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Min ( dcomplex  a,
dcomplex  b 
)

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Max ( dcomplex  a,
dcomplex  b 
)

template<>
int SAMRAI::tbox::MathUtilities< int >::Abs ( int  a  ) 

template<>
float SAMRAI::tbox::MathUtilities< float >::Abs ( float  a  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::Abs ( double  a  ) 

template<>
bool SAMRAI::tbox::MathUtilities< bool >::Rand ( const bool &  low,
const bool &  width 
)

template<>
char SAMRAI::tbox::MathUtilities< char >::Rand ( const char &  low,
const char &  width 
)

template<>
int SAMRAI::tbox::MathUtilities< int >::Rand ( const int &  low,
const int &  width 
)

template<>
float SAMRAI::tbox::MathUtilities< float >::Rand ( const float &  low,
const float &  width 
)

template<>
double SAMRAI::tbox::MathUtilities< double >::Rand ( const double &  low,
const double &  width 
)

template<>
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Rand ( const dcomplex low,
const dcomplex width 
)

template<>
float SAMRAI::tbox::MathUtilities< float >::round ( float  x  ) 

template<>
double SAMRAI::tbox::MathUtilities< double >::round ( double  x  ) 


The documentation for this class was generated from the following files:
Generated on Thu Jun 18 11:28:59 2009 for SAMRAI by  doxygen 1.5.1