summaryrefslogtreecommitdiff
path: root/zen/basic_math.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:22:18 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:22:18 +0200
commitbcc5cc28c6dc5178e8f4fd0cc521034ae5def388 (patch)
treebacc60d27b435d32172f97643576c5e4e953177d /zen/basic_math.h
parent5.9 (diff)
downloadFreeFileSync-bcc5cc28c6dc5178e8f4fd0cc521034ae5def388.tar.gz
FreeFileSync-bcc5cc28c6dc5178e8f4fd0cc521034ae5def388.tar.bz2
FreeFileSync-bcc5cc28c6dc5178e8f4fd0cc521034ae5def388.zip
5.10
Diffstat (limited to 'zen/basic_math.h')
-rw-r--r--zen/basic_math.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/zen/basic_math.h b/zen/basic_math.h
index 7923dc5d..bd416d19 100644
--- a/zen/basic_math.h
+++ b/zen/basic_math.h
@@ -32,6 +32,8 @@ const T& max(const T& a, const T& b, const T& c);
template <class T>
void confine(T& val, const T& minVal, const T& maxVal); //make sure minVal <= val && val <= maxVal
+template <class T>
+T confineCpy(const T& val, const T& minVal, const T& maxVal);
template <class InputIterator>
std::pair<InputIterator, InputIterator> minMaxElement(InputIterator first, InputIterator last);
@@ -97,6 +99,7 @@ const double ln2 = 0.693147180559945309417;
template <class T> inline
T abs(T value)
{
+ //static_assert(std::is_signed<T>::value, ""); might not compile for non-built-in arithmetic types; anyway "-value" should emit compiler error or warning for unsigned types
if (value < 0)
return -value; // operator "?:" caveat: may be different type than "value"
else
@@ -132,6 +135,17 @@ const T& max(const T& a, const T& b, const T& c)
template <class T> inline
+T confineCpy(const T& val, const T& minVal, const T& maxVal)
+{
+ assert(minVal <= maxVal);
+ if (val < minVal)
+ return minVal;
+ else if (val > maxVal)
+ return maxVal;
+ return val;
+}
+
+template <class T> inline
void confine(T& val, const T& minVal, const T& maxVal) //name trim?
{
assert(minVal <= maxVal);
bgstack15