#include <source/toolbox/base/MathUtilities.h>
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. |
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
TYPE SAMRAI::tbox::MathUtilities< TYPE >::getZero | ( | ) | [inline, static] |
Return the value 0 for the template type.
TYPE SAMRAI::tbox::MathUtilities< TYPE >::getOne | ( | ) | [inline, static] |
Return the value 1 for the template 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.
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.
value | Value to test |
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToSignalingNaN | ( | Array< TYPE > & | array | ) | [static] |
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToSignalingNaN | ( | TYPE * | array, | |
int | n = 1 | |||
) | [static] |
Set array entries to value given by getSignalingNaN().
array | Pointer to first array entry | |
n | Integer to number of array entries. |
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 ).
a | ||
b |
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.
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMax | ( | Array< TYPE > & | array | ) | [static] |
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMax | ( | TYPE * | array, | |
int | n = 1 | |||
) | [static] |
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.
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMin | ( | Array< TYPE > & | array | ) | [static] |
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToMin | ( | TYPE * | array, | |
int | n = 1 | |||
) | [static] |
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.
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToEpsilon | ( | Array< TYPE > & | array | ) | [static] |
void SAMRAI::tbox::MathUtilities< TYPE >::setArrayToEpsilon | ( | TYPE * | array, | |
int | n = 1 | |||
) | [static] |
Set array entries to value given by getEpsilon().
array | Pointer to first array entry | |
n | Integer to number of array entries. |
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.
a | ||
b |
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.
a | ||
b |
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.
a |
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.
a |
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.
low | Starting value for range | |
width | Width of the range. |
bool SAMRAI::tbox::MathUtilities< float >::isNaN | ( | const float & | value | ) |
bool SAMRAI::tbox::MathUtilities< double >::isNaN | ( | const double & | value | ) |
bool SAMRAI::tbox::MathUtilities< dcomplex >::isNaN | ( | const dcomplex & | value | ) |
bool SAMRAI::tbox::MathUtilities< float >::equalEps | ( | const float & | a, | |
const float & | b | |||
) |
bool SAMRAI::tbox::MathUtilities< double >::equalEps | ( | const double & | a, | |
const double & | b | |||
) |
bool SAMRAI::tbox::MathUtilities< dcomplex >::equalEps | ( | const dcomplex & | a, | |
const dcomplex & | b | |||
) |
bool SAMRAI::tbox::MathUtilities< bool >::Rand | ( | const bool & | low, | |
const bool & | width | |||
) |
char SAMRAI::tbox::MathUtilities< char >::Rand | ( | const char & | low, | |
const char & | width | |||
) |
int SAMRAI::tbox::MathUtilities< int >::Rand | ( | const int & | low, | |
const int & | width | |||
) |
float SAMRAI::tbox::MathUtilities< float >::Rand | ( | const float & | low, | |
const float & | width | |||
) |
double SAMRAI::tbox::MathUtilities< double >::Rand | ( | const double & | low, | |
const double & | width | |||
) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Rand | ( | const dcomplex & | low, | |
const dcomplex & | width | |||
) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Min | ( | dcomplex | a, | |
dcomplex | b | |||
) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Max | ( | dcomplex | a, | |
dcomplex | b | |||
) |
int SAMRAI::tbox::MathUtilities< int >::Abs | ( | int | a | ) |
float SAMRAI::tbox::MathUtilities< float >::Abs | ( | float | a | ) |
double SAMRAI::tbox::MathUtilities< double >::Abs | ( | double | a | ) |
float SAMRAI::tbox::MathUtilities< float >::round | ( | float | a | ) |
double SAMRAI::tbox::MathUtilities< double >::round | ( | double | a | ) |
bool SAMRAI::tbox::MathUtilities< bool >::s_zero | ( | ) |
bool SAMRAI::tbox::MathUtilities< bool >::s_one | ( | ) |
bool SAMRAI::tbox::MathUtilities< bool >::s_signaling_nan | ( | ) |
bool SAMRAI::tbox::MathUtilities< bool >::s_max | ( | ) |
bool SAMRAI::tbox::MathUtilities< bool >::s_min | ( | ) |
bool SAMRAI::tbox::MathUtilities< bool >::s_epsilon | ( | ) |
char SAMRAI::tbox::MathUtilities< char >::s_zero | ( | ) |
char SAMRAI::tbox::MathUtilities< char >::s_one | ( | ) |
char SAMRAI::tbox::MathUtilities< char >::s_signaling_nan | ( | ) |
char SAMRAI::tbox::MathUtilities< char >::s_max | ( | ) |
char SAMRAI::tbox::MathUtilities< char >::s_min | ( | ) |
char SAMRAI::tbox::MathUtilities< char >::s_epsilon | ( | ) |
int SAMRAI::tbox::MathUtilities< int >::s_zero | ( | ) |
int SAMRAI::tbox::MathUtilities< int >::s_one | ( | ) |
int SAMRAI::tbox::MathUtilities< int >::s_signaling_nan | ( | ) |
int SAMRAI::tbox::MathUtilities< int >::s_max | ( | ) |
int SAMRAI::tbox::MathUtilities< int >::s_min | ( | ) |
int SAMRAI::tbox::MathUtilities< int >::s_epsilon | ( | ) |
float SAMRAI::tbox::MathUtilities< float >::s_zero | ( | ) |
float SAMRAI::tbox::MathUtilities< float >::s_one | ( | ) |
float SAMRAI::tbox::MathUtilities< float >::s_signaling_nan | ( | ) |
float SAMRAI::tbox::MathUtilities< float >::s_max | ( | ) |
float SAMRAI::tbox::MathUtilities< float >::s_min | ( | ) |
float SAMRAI::tbox::MathUtilities< float >::s_epsilon | ( | ) |
double SAMRAI::tbox::MathUtilities< double >::s_zero | ( | ) |
double SAMRAI::tbox::MathUtilities< double >::s_one | ( | ) |
double SAMRAI::tbox::MathUtilities< double >::s_signaling_nan | ( | ) |
double SAMRAI::tbox::MathUtilities< double >::s_max | ( | ) |
double SAMRAI::tbox::MathUtilities< double >::s_min | ( | ) |
double SAMRAI::tbox::MathUtilities< double >::s_epsilon | ( | ) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_zero | ( | ) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_one | ( | ) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_signaling_nan | ( | ) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_max | ( | ) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_min | ( | ) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::s_epsilon | ( | ) |
bool SAMRAI::tbox::MathUtilities< float >::isNaN | ( | const float & | value | ) |
bool SAMRAI::tbox::MathUtilities< double >::isNaN | ( | const double & | value | ) |
bool SAMRAI::tbox::MathUtilities< dcomplex >::isNaN | ( | const dcomplex & | value | ) |
bool SAMRAI::tbox::MathUtilities< float >::equalEps | ( | const float & | a, | |
const float & | b | |||
) |
bool SAMRAI::tbox::MathUtilities< double >::equalEps | ( | const double & | a, | |
const double & | b | |||
) |
bool SAMRAI::tbox::MathUtilities< dcomplex >::equalEps | ( | const dcomplex & | a, | |
const dcomplex & | b | |||
) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Min | ( | dcomplex | a, | |
dcomplex | b | |||
) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Max | ( | dcomplex | a, | |
dcomplex | b | |||
) |
int SAMRAI::tbox::MathUtilities< int >::Abs | ( | int | a | ) |
float SAMRAI::tbox::MathUtilities< float >::Abs | ( | float | a | ) |
double SAMRAI::tbox::MathUtilities< double >::Abs | ( | double | a | ) |
bool SAMRAI::tbox::MathUtilities< bool >::Rand | ( | const bool & | low, | |
const bool & | width | |||
) |
char SAMRAI::tbox::MathUtilities< char >::Rand | ( | const char & | low, | |
const char & | width | |||
) |
int SAMRAI::tbox::MathUtilities< int >::Rand | ( | const int & | low, | |
const int & | width | |||
) |
float SAMRAI::tbox::MathUtilities< float >::Rand | ( | const float & | low, | |
const float & | width | |||
) |
double SAMRAI::tbox::MathUtilities< double >::Rand | ( | const double & | low, | |
const double & | width | |||
) |
dcomplex SAMRAI::tbox::MathUtilities< dcomplex >::Rand | ( | const dcomplex & | low, | |
const dcomplex & | width | |||
) |
float SAMRAI::tbox::MathUtilities< float >::round | ( | float | x | ) |
double SAMRAI::tbox::MathUtilities< double >::round | ( | double | x | ) |