diff options
author | Daniel Wilhelm <shieldwed@outlook.com> | 2018-05-09 00:09:55 +0200 |
---|---|---|
committer | Daniel Wilhelm <shieldwed@outlook.com> | 2018-05-09 00:09:55 +0200 |
commit | 9b623ea3943165fe7efb5e47a0b5b9452c1599e6 (patch) | |
tree | dde40e07e907ac6e0ca9ea32524f2cd4810d4be6 /zen/basic_math.h | |
parent | 9.7 (diff) | |
download | FreeFileSync-9b623ea3943165fe7efb5e47a0b5b9452c1599e6.tar.gz FreeFileSync-9b623ea3943165fe7efb5e47a0b5b9452c1599e6.tar.bz2 FreeFileSync-9b623ea3943165fe7efb5e47a0b5b9452c1599e6.zip |
9.8
Diffstat (limited to 'zen/basic_math.h')
-rwxr-xr-x | zen/basic_math.h | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/zen/basic_math.h b/zen/basic_math.h index 1b6b7e97..16f69bde 100755 --- a/zen/basic_math.h +++ b/zen/basic_math.h @@ -31,7 +31,7 @@ template <class T> T clampCpy(T val, T minVal, T maxVal); template <class T, class InputIterator> //precondition: range must be sorted! auto nearMatch(const T& val, InputIterator first, InputIterator last); -int round(double d); //"little rounding function" +int64_t round(double d); //"little rounding function" template <class N, class D> auto integerDivideRoundUp(N numerator, D denominator); @@ -182,7 +182,7 @@ std::pair<InputIterator, InputIterator> minMaxElement(InputIterator first, Input } } } - return std::make_pair(lowest, largest); + return { lowest, largest }; } @@ -220,20 +220,20 @@ bool isNull(T value) inline -int round(double d) +int64_t round(double d) { - assert(d - 0.5 >= std::numeric_limits<int>::min() && //if double is larger than what int can represent: - d + 0.5 <= std::numeric_limits<int>::max()); //=> undefined behavior! - return static_cast<int>(d < 0 ? d - 0.5 : d + 0.5); + assert(d - 0.5 >= std::numeric_limits<int64_t>::min() && //if double is larger than what int can represent: + d + 0.5 <= std::numeric_limits<int64_t>::max()); //=> undefined behavior! + return static_cast<int64_t>(d < 0 ? d - 0.5 : d + 0.5); } template <class N, class D> inline auto integerDivideRoundUp(N numerator, D denominator) { - static_assert(std::is_integral<N>::value && std::is_unsigned<N>::value, ""); - static_assert(std::is_integral<D>::value && std::is_unsigned<D>::value, ""); - assert(denominator > 0); + static_assert(std::is_integral<N>::value, ""); + static_assert(std::is_integral<D>::value, ""); + assert(numerator > 0 && denominator > 0); return (numerator + denominator - 1) / denominator; } |