Support initial NaN range with range::expand

This commit is contained in:
Danny Robson 2012-05-23 20:41:11 +10:00
parent 124878fc98
commit ea9d6c175d
2 changed files with 13 additions and 2 deletions

View File

@ -80,8 +80,10 @@ range<T>::clamp (T val) const
template <typename T>
void
range<T>::expand (T val) {
min = std::min (min, val);
max = std::max (max, val);
// The arguments to min and max are such that expansion from initial NaN
// values should change both min and max to be that value.
min = std::min (val, min);
max = std::max (val, max);
}

View File

@ -27,6 +27,15 @@ main (int, char **) {
CHECK_HARD ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::min()));
CHECK_HARD ( range<uint16_t>::UNLIMITED.contains (numeric_limits<uint16_t>::max()));
{
range<double> initial_nan (numeric_limits<double>::quiet_NaN (),
numeric_limits<double>::quiet_NaN ());
initial_nan.expand (1.0);
CHECK_EQ (initial_nan.min, 1.0);
CHECK_EQ (initial_nan.max, 1.0);
}
return EXIT_SUCCESS;
}