|
@@ -700,6 +700,33 @@ namespace vstd
|
|
|
return a + (b - a) * f;
|
|
|
}
|
|
|
|
|
|
+ /// Divides dividend by divisor and rounds result up
|
|
|
+ /// For use with integer-only arithmetic
|
|
|
+ template<typename Integer1, typename Integer2>
|
|
|
+ Integer1 divideAndCeil(const Integer1 & dividend, const Integer2 & divisor)
|
|
|
+ {
|
|
|
+ static_assert(std::is_integral_v<Integer1> && std::is_integral_v<Integer2>, "This function should only be used with integral types");
|
|
|
+ return (dividend + divisor - 1) / divisor;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Divides dividend by divisor and rounds result to nearest
|
|
|
+ /// For use with integer-only arithmetic
|
|
|
+ template<typename Integer1, typename Integer2>
|
|
|
+ Integer1 divideAndRound(const Integer1 & dividend, const Integer2 & divisor)
|
|
|
+ {
|
|
|
+ static_assert(std::is_integral_v<Integer1> && std::is_integral_v<Integer2>, "This function should only be used with integral types");
|
|
|
+ return (dividend + divisor / 2 - 1) / divisor;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Divides dividend by divisor and rounds result down
|
|
|
+ /// For use with integer-only arithmetic
|
|
|
+ template<typename Integer1, typename Integer2>
|
|
|
+ Integer1 divideAndFloor(const Integer1 & dividend, const Integer2 & divisor)
|
|
|
+ {
|
|
|
+ static_assert(std::is_integral_v<Integer1> && std::is_integral_v<Integer2>, "This function should only be used with integral types");
|
|
|
+ return dividend / divisor;
|
|
|
+ }
|
|
|
+
|
|
|
template<typename Floating>
|
|
|
bool isAlmostZero(const Floating & value)
|
|
|
{
|