From a5c574f98da576111580d6cfab364e22ee05d785 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sun, 3 Aug 2014 00:07:50 +0200 Subject: [PATCH] windows compilation fix --- include/mitsuba/core/math.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/include/mitsuba/core/math.h b/include/mitsuba/core/math.h index a0a7e4a6..cf887b38 100644 --- a/include/mitsuba/core/math.h +++ b/include/mitsuba/core/math.h @@ -103,10 +103,22 @@ template inline int floorToInt(Scalar value) { return (int) st template inline int ceilToInt(Scalar value) { return (int) std::ceil(value); } /// Integer round function (single precision) -inline int roundToInt(float value) { return (int) ::roundf(value); } +inline int roundToInt(float value) { + #if defined(__MSVC__) + return (int) (value < 0.0f ? std::ceil(value - 0.5f) : std::floor(value + 0.5f)); + #else + return (int) ::roundf(value); + #endif +} /// Integer round function (double precision) -inline int roundToInt(double value) { return (int) ::round(value); } +inline int roundToInt(double value) { + #if defined(__MSVC__) + return (int) (value < 0.0f ? std::ceil(value - 0.5f) : std::floor(value + 0.5f)); + #else + return (int) ::round(value); + #endif +} /// Base-2 logarithm (32-bit integer version) extern MTS_EXPORT_CORE int log2i(uint32_t value);