From bd00c8e572ef27f643be123f923b9fc26fe4583c Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 25 Nov 2012 00:04:18 +0100 Subject: [PATCH] Added rounding functions. --- .../PolyVoxCore/include/PolyVoxCore/Impl/Utility.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h index 7d243c79..915c20ab 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h @@ -32,6 +32,19 @@ namespace PolyVox { POLYVOX_API uint8_t logBase2(uint32_t uInput); POLYVOX_API bool isPowerOf2(uint32_t uInput); + + int32_t roundTowardsNegInf(float r); + int32_t roundToInteger(float r); + + inline int32_t roundTowardsNegInf(float r) + { + return (r > 0.0) ? static_cast(r) : static_cast(r - 1.0f); + } + + inline int32_t roundToNearestInteger(float r) + { + return (r > 0.0) ? static_cast(r + 0.5f) : static_cast(r - 0.5f); + } } #endif