summaryrefslogtreecommitdiff
path: root/zen/basic_math.h
diff options
context:
space:
mode:
Diffstat (limited to 'zen/basic_math.h')
-rw-r--r--zen/basic_math.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/zen/basic_math.h b/zen/basic_math.h
index 41f42dbe..9a3d195e 100644
--- a/zen/basic_math.h
+++ b/zen/basic_math.h
@@ -1,6 +1,6 @@
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
-// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// **************************************************************************
@@ -42,7 +42,10 @@ auto nearMatch(const T& val, InputIterator first, InputIterator last) -> typenam
template <class T>
bool isNull(T value);
-int round(double d); //little rounding function
+int round(double d); //"little rounding function"
+
+template <class N>
+N integerDivideRoundUp(N numerator, N denominator);
template <size_t N, class T>
T power(const T& value);
@@ -98,7 +101,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
+ static_assert(std::is_signed<T>::value, "");
if (value < 0)
return -value; // operator "?:" caveat: may be different type than "value"
else
@@ -234,6 +237,15 @@ int round(double d)
}
+template <class N> inline
+N integerDivideRoundUp(N numerator, N denominator)
+{
+ static_assert(std::is_unsigned<N>::value, "");
+ assert(denominator > 0);
+ return (numerator + denominator - 1) / denominator;
+}
+
+
namespace
{
template <size_t N, class T>
bgstack15