From 75d69bf9df56912b9fcfb134741d714ba4e2fa5a Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Thu, 5 Feb 2015 20:30:45 +1100 Subject: [PATCH] maths: fix the ordering of limit --- maths.cpp | 2 ++ maths.hpp | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/maths.cpp b/maths.cpp index b33c64c7..9e89ff88 100644 --- a/maths.cpp +++ b/maths.cpp @@ -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); diff --git a/maths.hpp b/maths.hpp index a7c5b756..d5f54b1c 100644 --- a/maths.hpp +++ b/maths.hpp @@ -276,10 +276,18 @@ max [[gnu::pure]] (const T a, const U b, Args ...args) //----------------------------------------------------------------------------- +// Limiting functions + +// min/max clamping template 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;