maths: fix the ordering of limit

This commit is contained in:
Danny Robson 2015-02-05 20:30:45 +11:00
parent 8487f700f6
commit 75d69bf9df
2 changed files with 11 additions and 1 deletions

View File

@ -182,5 +182,7 @@ template int sign (int);
// so it's easier to instantiate early and check for broken code at library
// build time.
template float limit (float, float, float);
template float smoothstep (float, float, float);
template double smoothstep (double, double, double);

View File

@ -276,10 +276,18 @@ max [[gnu::pure]] (const T a, const U b, Args ...args)
//-----------------------------------------------------------------------------
// Limiting functions
// min/max clamping
template <typename T, typename U, typename V>
T
limit [[gnu::pure]] (const T val, const U hi, const V lo)
limit [[gnu::pure]] (const T val, const U lo, const V hi)
{
CHECK_LE(
decltype (lo+hi) (lo),
decltype (hi+lo) (hi)
);
return val > hi ? hi:
val < lo ? lo:
val;