Support initial NaN range with range::expand
This commit is contained in:
parent
124878fc98
commit
ea9d6c175d
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user