You can use sentinel values only for setting/getting values to floating point numbers, and to do equal/not-equal operations. This class ensures that sentinels are used such that round-off errors are handled.
SentinelDouble MissingTemperature( -999, 0.1 ); double v = getTemperature(); if ( v != MissingTemperature ){ return ( 1.4*v + 32 ); } else return 72;
Public Member Functions | |
SentinelDouble (int value_in, double tolerance_in) | |
the input value has to be an integer value. | |
SentinelDouble () | |
For STL use only -- variables remain uninitialized! | |
operator const int & () const | |
WARNING! this is meant for use simply to set values i.e. | |
Friends | |
template<class T> | |
bool | operator== (const SentinelDouble &a, T b) |
overload comparision for char, short, int, float and double | |
template<class T> | |
bool | operator== (T b, const SentinelDouble &a) |
template<class T> | |
bool | operator!= (const SentinelDouble &a, T b) |
template<class T> | |
bool | operator!= (T b, const SentinelDouble &a) |
code::SentinelDouble::SentinelDouble | ( | int | value_in, | |
double | tolerance_in | |||
) | [inline] |
the input value has to be an integer value.
This class allows comparisions with doubles in a tolerant way.
code::SentinelDouble::SentinelDouble | ( | ) | [inline] |
For STL use only -- variables remain uninitialized!
code::SentinelDouble::operator const int & | ( | ) | const [inline] |
WARNING! this is meant for use simply to set values i.e.
double m = Constants::MissingData Do not use m for future comparisions. Use the value wrapped within the class (Constants::MissingData) for all comparisions.
bool operator!= | ( | T | b, | |
const SentinelDouble & | a | |||
) | [friend] |
bool operator!= | ( | const SentinelDouble & | a, | |
T | b | |||
) | [friend] |
bool operator== | ( | T | b, | |
const SentinelDouble & | a | |||
) | [friend] |
bool operator== | ( | const SentinelDouble & | a, | |
T | b | |||
) | [friend] |
overload comparision for char, short, int, float and double