Add MAX range object
This commit is contained in:
parent
7d61acc8c1
commit
c0dcdd89d9
14
range.cpp
14
range.cpp
@ -177,10 +177,16 @@ range<T>::operator ==(const range<T> &rhs) const
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const range<T>
|
const range<T>
|
||||||
range<T>::UNLIMITED (numeric_limits <T>::is_integer ? numeric_limits <T>::min () :
|
range<T>::UNLIMITED (numeric_limits<T>::has_infinity ? -numeric_limits<T>::infinity () :
|
||||||
-numeric_limits <T>::infinity (),
|
numeric_limits<T>::lowest (),
|
||||||
numeric_limits <T>::is_integer ? numeric_limits <T>::max () :
|
numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity () :
|
||||||
numeric_limits <T>::infinity ());
|
numeric_limits<T>::max ());
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
const range<T>
|
||||||
|
range<T>::MAX (numeric_limits<T>::lowest (),
|
||||||
|
numeric_limits<T>::max ());
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
const range<T>
|
const range<T>
|
||||||
|
@ -74,6 +74,7 @@ namespace util {
|
|||||||
|
|
||||||
/// A range which is guaranteed to contain all elements type T
|
/// A range which is guaranteed to contain all elements type T
|
||||||
static const range<T> UNLIMITED;
|
static const range<T> UNLIMITED;
|
||||||
|
static const range<T> MAX;
|
||||||
/// A range which only contains elements between 0 and 1 inclusive
|
/// A range which only contains elements between 0 and 1 inclusive
|
||||||
static const range<T> UNIT;
|
static const range<T> UNIT;
|
||||||
|
|
||||||
|
@ -9,25 +9,38 @@ using namespace util;
|
|||||||
|
|
||||||
int
|
int
|
||||||
main (int, char **) {
|
main (int, char **) {
|
||||||
|
// Check some simple cases close to the edges of a unit range. Tests float rounding.
|
||||||
CHECK_HARD ( range<double>::UNIT.contains ( 0.0));
|
CHECK_HARD ( range<double>::UNIT.contains ( 0.0));
|
||||||
CHECK_HARD ( range<double>::UNIT.contains ( 0.5));
|
CHECK_HARD ( range<double>::UNIT.contains ( 0.5));
|
||||||
CHECK_HARD ( range<double>::UNIT.contains ( 1.0));
|
CHECK_HARD ( range<double>::UNIT.contains ( 1.0));
|
||||||
|
CHECK_HARD ( range<double>::UNIT.contains (std::numeric_limits<double>::min ()));
|
||||||
CHECK_HARD (!range<double>::UNIT.contains (-0.00001));
|
CHECK_HARD (!range<double>::UNIT.contains (-0.00001));
|
||||||
CHECK_HARD (!range<double>::UNIT.contains ( 1.00001));
|
CHECK_HARD (!range<double>::UNIT.contains ( 1.00001));
|
||||||
|
|
||||||
|
// Check edge cases of unit with integer values
|
||||||
CHECK_HARD ( range<uint16_t>::UNIT.contains (0));
|
CHECK_HARD ( range<uint16_t>::UNIT.contains (0));
|
||||||
CHECK_HARD ( range<uint16_t>::UNIT.contains (1));
|
CHECK_HARD ( range<uint16_t>::UNIT.contains (1));
|
||||||
CHECK_HARD (!range<uint16_t>::UNIT.contains (2));
|
CHECK_HARD (!range<uint16_t>::UNIT.contains (2));
|
||||||
CHECK_HARD (!range<uint16_t>::UNIT.contains (numeric_limits <uint16_t>::max ()));
|
CHECK_HARD (!range<uint16_t>::UNIT.contains (numeric_limits <uint16_t>::max ()));
|
||||||
|
|
||||||
|
// Check the inclusivity of UNLIMITED with special floating values
|
||||||
CHECK_HARD ( range<double>::UNLIMITED.contains (0.0));
|
CHECK_HARD ( range<double>::UNLIMITED.contains (0.0));
|
||||||
CHECK_HARD ( range<double>::UNLIMITED.contains (+numeric_limits<double>::infinity ()));
|
CHECK_HARD ( range<double>::UNLIMITED.contains (+numeric_limits<double>::infinity ()));
|
||||||
CHECK_HARD ( range<double>::UNLIMITED.contains (-numeric_limits<double>::infinity ()));
|
CHECK_HARD ( range<double>::UNLIMITED.contains (-numeric_limits<double>::infinity ()));
|
||||||
CHECK_HARD (!range<double>::UNLIMITED.contains ( numeric_limits<double>::quiet_NaN ()));
|
CHECK_HARD (!range<double>::UNLIMITED.contains ( numeric_limits<double>::quiet_NaN ()));
|
||||||
|
|
||||||
|
// Check the inclusivity of UNLIMITED with some large numbers
|
||||||
CHECK_HARD ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::min()));
|
CHECK_HARD ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::min()));
|
||||||
CHECK_HARD ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::max()));
|
CHECK_HARD ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::max()));
|
||||||
|
|
||||||
|
// Check inclusivity of MAX
|
||||||
|
CHECK_HARD (!range<double>::MAX.contains ( numeric_limits<double>::infinity ()));
|
||||||
|
CHECK_HARD (!range<double>::MAX.contains (-numeric_limits<double>::infinity ()));
|
||||||
|
|
||||||
|
CHECK_HARD ( range<uint16_t>::MAX.contains (numeric_limits<uint16_t>::min()));
|
||||||
|
CHECK_HARD ( range<uint16_t>::MAX.contains (numeric_limits<uint16_t>::max()));
|
||||||
|
|
||||||
|
// Check that expansion via NaN is a noop
|
||||||
{
|
{
|
||||||
range<double> initial_nan (numeric_limits<double>::quiet_NaN (),
|
range<double> initial_nan (numeric_limits<double>::quiet_NaN (),
|
||||||
numeric_limits<double>::quiet_NaN ());
|
numeric_limits<double>::quiet_NaN ());
|
||||||
|
Loading…
Reference in New Issue
Block a user