diff options
author | Uwe Klotz <uwe_klotz@web.de> | 2014-11-17 11:09:23 +0100 |
---|---|---|
committer | Uwe Klotz <uwe_klotz@web.de> | 2014-11-17 21:35:50 +0100 |
commit | 25f59572e516c3942c039ea96bb75a53feff5509 (patch) | |
tree | 90156cc49dfc0bc02b96c926524ae368e7d8fd4f /src/util/math.h | |
parent | 749374af3851dfd7bbc3ee958e39bba54e9f497e (diff) |
Replace obsolete comment
Diffstat (limited to 'src/util/math.h')
-rw-r--r-- | src/util/math.h | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/util/math.h b/src/util/math.h index 08846aa854..9504b444a7 100644 --- a/src/util/math.h +++ b/src/util/math.h @@ -17,15 +17,17 @@ using std::fabs; #define math_min std::min #define math_max3(a, b, c) math_max(math_max((a), (b)), (c)) +// Restrict value to the range [min, max]. Undefined behavior +// if min > max. template <typename T> inline T math_clamp_unsafe(T value, T min, T max) { return math_max(min, math_min(max, value)); } +// Clamp with bounds checking to avoid undefined behavior +// on invalid min/max parameters. template <typename T> inline T math_clamp_safe(T value, T min, T max) { - // XXX: If max < min, behavior is undefined, and has been causing problems. - // if debugging is on, assert when this happens. if (min <= max) { // valid bounds return math_clamp_unsafe(value, min, max); |