Fix several MSVC issues numeric.h
authorSmallJoker <mk939@ymail.com>
Wed, 29 Apr 2015 17:28:25 +0000 (19:28 +0200)
committerest31 <MTest31@outlook.com>
Fri, 1 May 2015 05:34:51 +0000 (07:34 +0200)
-> Round negative numbers correctly CMakeLists.txt
-> Link Json with the static run-time library

src/json/CMakeLists.txt
src/unittest/test_utilities.cpp
src/util/numeric.h

index 206c6ea9cdd22260eea5f5ec03e43d1d3f24f242..de99c7f0c611c5f9f46d03ee46fd86b109a2cc85 100644 (file)
@@ -1,4 +1,7 @@
-add_library(jsoncpp jsoncpp.cpp)
+if(MSVC)
+       set(CMAKE_CXX_FLAGS_RELEASE "/MT")
+endif()
 
+add_library(jsoncpp jsoncpp.cpp)
 target_link_libraries(jsoncpp)
 
index caf4515c877baa172eca316f229717c69e5e037c..07108706a5c9ef4803fa7f17d67d6d4421dff59c 100644 (file)
@@ -45,6 +45,7 @@ public:
        void testWrapRows();
        void testIsNumber();
        void testIsPowerOfTwo();
+       void testMyround();
 };
 
 static TestUtilities g_test_instance;
@@ -67,6 +68,7 @@ void TestUtilities::runTests(IGameDef *gamedef)
        TEST(testWrapRows);
        TEST(testIsNumber);
        TEST(testIsPowerOfTwo);
+       TEST(testMyround);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -239,3 +241,12 @@ void TestUtilities::testIsPowerOfTwo()
        }
        UASSERT(is_power_of_two((u32)-1) == false);
 }
+
+void TestUtilities::testMyround()
+{
+       UASSERT(myround(4.6f) == 5);
+       UASSERT(myround(1.2f) == 1);
+       UASSERT(myround(-3.1f) == -3);
+       UASSERT(myround(-6.5f) == -7);
+}
+
index b4b8419188526965996e28f693f37b5ed96d8639..0eba01359ea6db92c9cfcf67c0ac157df04ca738 100644 (file)
@@ -288,7 +288,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
 */
 inline s32 myround(f32 f)
 {
-       return floor(f + 0.5);
+       return (s32)(f < 0.f ? (f - 0.5f) : (f + 0.5f));
 }
 
 /*