IBAMR  IBAMR version 0.19.
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
SAMRAI::tbox::MathUtilities< TYPE > Class Template Reference

#include <tbox/MathUtilities.h>

Public Member Functions

bool isNaN (const float &value)
 
bool isNaN (const double &value)
 
bool isNaN (const dcomplex &value)
 
bool equalEps (const float &a, const float &b)
 
bool equalEps (const double &a, const double &b)
 
bool equalEps (const dcomplex &a, const dcomplex &b)
 
bool Rand (const bool &low, const bool &width)
 
char Rand (const char &low, const char &width)
 
int Rand (const int &low, const int &width)
 
float Rand (const float &low, const float &width)
 
double Rand (const double &low, const double &width)
 
dcomplex Rand (const dcomplex &low, const dcomplex &width)
 
dcomplex Min (dcomplex a, dcomplex b)
 
dcomplex Max (dcomplex a, dcomplex b)
 
int Abs (int a)
 
float Abs (float a)
 
double Abs (double a)
 
float round (float a)
 
double round (double a)
 

Static Public Member Functions

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

Private Member Functions

bool s_zero
 
bool s_one
 
bool s_signaling_nan
 
bool s_max
 
bool s_min
 
bool s_epsilon
 
char s_zero
 
char s_one
 
char s_signaling_nan
 
char s_max
 
char s_min
 
char s_epsilon
 
int s_zero
 
int s_one
 
int s_signaling_nan
 
int s_max
 
int s_min
 
int s_epsilon
 
float s_zero
 
float s_one
 
float s_signaling_nan
 
float s_max
 
float s_min
 
float s_epsilon
 
double s_zero
 
double s_one
 
double s_signaling_nan
 
double s_max
 
double s_min
 
double s_epsilon
 
dcomplex s_zero
 
dcomplex s_one
 
dcomplex s_signaling_nan
 
dcomplex s_max
 
dcomplex s_min
 
dcomplex s_epsilon
 

Static Private Attributes

static TYPE s_zero
 
static TYPE s_one
 
static TYPE s_signaling_nan
 
static TYPE s_max
 
static TYPE s_min
 
static TYPE s_epsilon
 

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

◆ getZero()

template<class TYPE >
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::getZero ( )
static

◆ getOne()

template<class TYPE >
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::getOne ( )
static

◆ getSignalingNaN()

template<class TYPE >
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::getSignalingNaN ( )
static

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.

◆ isNaN() [1/4]

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

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
valueValue to test

◆ setArrayToSignalingNaN() [1/2]

template<class TYPE >
static void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToSignalingNaN ( Array< TYPE > &  array)
static
Parameters
arraySAMRAI array to set

◆ setArrayToSignalingNaN() [2/2]

template<class TYPE >
static void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToSignalingNaN ( TYPE *  array,
int  n = 1 
)
static
Parameters
arrayPointer to first array entry
nInteger to number of array entries.

◆ equalEps() [1/4]

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

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

◆ getMax()

template<class TYPE >
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::getMax ( )
static

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.

◆ setArrayToMax() [1/2]

template<class TYPE >
static void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMax ( Array< TYPE > &  array)
static
Parameters
arraySAMRAI array to set

◆ setArrayToMax() [2/2]

template<class TYPE >
static void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMax ( TYPE *  array,
int  n = 1 
)
static
Parameters
arrayPointer to first array entry
nInteger to number of array entries.

◆ getMin()

template<class TYPE >
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::getMin ( )
static

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.

◆ setArrayToMin() [1/2]

template<class TYPE >
static void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMin ( Array< TYPE > &  array)
static
Parameters
arraySAMRAI array to set

◆ setArrayToMin() [2/2]

template<class TYPE >
static void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMin ( TYPE *  array,
int  n = 1 
)
static
Parameters
arrayPointer to first array entry
nInteger to number of array entries.

◆ getEpsilon()

template<class TYPE >
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::getEpsilon ( )
static

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.

◆ setArrayToEpsilon() [1/2]

template<class TYPE >
static void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToEpsilon ( Array< TYPE > &  array)
static
Parameters
arraySAMRAI array to set

◆ setArrayToEpsilon() [2/2]

template<class TYPE >
static void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToEpsilon ( TYPE *  array,
int  n = 1 
)
static
Parameters
arrayPointer to first array entry
nInteger to number of array entries.

◆ Min() [1/2]

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

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

Parameters
a
b

◆ Max() [1/2]

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

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

Parameters
a
b

◆ Abs() [1/4]

template<class TYPE >
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::Abs ( TYPE  a)
static

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

Parameters
a

◆ round() [1/3]

template<class TYPE >
static TYPE SAMRAI::tbox::MathUtilities< TYPE >::round ( TYPE  a)
static

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

◆ Rand() [1/7]

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

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
lowStarting value for range
widthWidth of the range.

◆ isNaN() [2/4]

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

◆ isNaN() [3/4]

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

◆ isNaN() [4/4]

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

◆ equalEps() [2/4]

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

◆ equalEps() [3/4]

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

◆ equalEps() [4/4]

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

◆ Rand() [2/7]

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

◆ Rand() [3/7]

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

◆ Rand() [4/7]

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

◆ Rand() [5/7]

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

◆ Rand() [6/7]

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

◆ Rand() [7/7]

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

◆ Min() [2/2]

◆ Max() [2/2]

◆ Abs() [2/4]

◆ Abs() [3/4]

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

◆ Abs() [4/4]

◆ round() [2/3]

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

◆ round() [3/3]

◆ s_zero() [1/6]

◆ s_one() [1/6]

◆ s_signaling_nan() [1/6]

bool SAMRAI::tbox::MathUtilities< bool >::s_signaling_nan
private

◆ s_max() [1/6]

◆ s_min() [1/6]

◆ s_epsilon() [1/6]

bool SAMRAI::tbox::MathUtilities< bool >::s_epsilon
private

◆ s_zero() [2/6]

char SAMRAI::tbox::MathUtilities< char >::s_zero
private

◆ s_one() [2/6]

char SAMRAI::tbox::MathUtilities< char >::s_one
private

◆ s_signaling_nan() [2/6]

char SAMRAI::tbox::MathUtilities< char >::s_signaling_nan
private

◆ s_max() [2/6]

char SAMRAI::tbox::MathUtilities< char >::s_max
private

◆ s_min() [2/6]

char SAMRAI::tbox::MathUtilities< char >::s_min
private

◆ s_epsilon() [2/6]

char SAMRAI::tbox::MathUtilities< char >::s_epsilon
private

◆ s_zero() [3/6]

int SAMRAI::tbox::MathUtilities< int >::s_zero
private

◆ s_one() [3/6]

int SAMRAI::tbox::MathUtilities< int >::s_one
private

◆ s_signaling_nan() [3/6]

int SAMRAI::tbox::MathUtilities< int >::s_signaling_nan
private

◆ s_max() [3/6]

int SAMRAI::tbox::MathUtilities< int >::s_max
private

◆ s_min() [3/6]

int SAMRAI::tbox::MathUtilities< int >::s_min
private

◆ s_epsilon() [3/6]

int SAMRAI::tbox::MathUtilities< int >::s_epsilon
private

◆ s_zero() [4/6]

float SAMRAI::tbox::MathUtilities< float >::s_zero
private

◆ s_one() [4/6]

float SAMRAI::tbox::MathUtilities< float >::s_one
private

◆ s_signaling_nan() [4/6]

float SAMRAI::tbox::MathUtilities< float >::s_signaling_nan
private

◆ s_max() [4/6]

float SAMRAI::tbox::MathUtilities< float >::s_max
private

◆ s_min() [4/6]

float SAMRAI::tbox::MathUtilities< float >::s_min
private

◆ s_epsilon() [4/6]

float SAMRAI::tbox::MathUtilities< float >::s_epsilon
private

◆ s_zero() [5/6]

◆ s_one() [5/6]

◆ s_signaling_nan() [5/6]

double SAMRAI::tbox::MathUtilities< double >::s_signaling_nan
private

◆ s_max() [5/6]

◆ s_min() [5/6]

◆ s_epsilon() [5/6]

double SAMRAI::tbox::MathUtilities< double >::s_epsilon
private

◆ s_zero() [6/6]

◆ s_one() [6/6]

◆ s_signaling_nan() [6/6]

dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_signaling_nan
private

◆ s_max() [6/6]

◆ s_min() [6/6]

◆ s_epsilon() [6/6]

Member Data Documentation

◆ s_zero

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

◆ s_one

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

◆ s_signaling_nan

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

◆ s_max

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

◆ s_min

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

◆ s_epsilon

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

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