Add more scalar operators for range

This commit is contained in:
Danny Robson 2012-05-24 15:03:26 +10:00
parent ea9d6c175d
commit aabbf231c5
2 changed files with 30 additions and 0 deletions

View File

@ -95,6 +95,23 @@ range<T>::normalise (T val) const {
} }
template <typename T>
range<T>&
range<T>::operator*= (T val) {
min *= val;
max *= val;
return *this;
}
template <typename T>
range<T>
range<T>::operator* (T val) const {
return range<T> (min * val, max * val);
}
namespace util { namespace util {
template <> template <>
double double

View File

@ -48,9 +48,22 @@ namespace util {
/// Expand the range to include this value if necessary /// Expand the range to include this value if necessary
void expand (T val); void expand (T val);
/// Normalise a number to [0, 1] within the range. Does not check bounds. /// Normalise a number to [0, 1] within the range. Does not check bounds.
double normalise (T val) const; double normalise (T val) const;
range& operator*= (T);
range operator* (T) const;
range& operator/= (T);
range operator/ (T) const;
range& operator+= (T);
range operator+ (T) const;
range& operator-= (T);
range operator- (T) const;
/// Return a pseudo-random uniformly distributed value within the range. /// Return a pseudo-random uniformly distributed value within the range.
/// There are no statistical randomness guarantees whatsoever. /// There are no statistical randomness guarantees whatsoever.
T random (void) const; T random (void) const;