Fix several MSVC issues numeric.h

-> Round negative numbers correctly CMakeLists.txt
-> Link Json with the static run-time library
This commit is contained in:
SmallJoker 2015-04-29 19:28:25 +02:00 committed by est31
parent 37ca3212ee
commit 6626a3f72f
3 changed files with 16 additions and 2 deletions

View 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) target_link_libraries(jsoncpp)

View File

@ -45,6 +45,7 @@ class TestUtilities : public TestBase {
void testWrapRows(); void testWrapRows();
void testIsNumber(); void testIsNumber();
void testIsPowerOfTwo(); void testIsPowerOfTwo();
void testMyround();
}; };
static TestUtilities g_test_instance; static TestUtilities g_test_instance;
@ -67,6 +68,7 @@ void TestUtilities::runTests(IGameDef *gamedef)
TEST(testWrapRows); TEST(testWrapRows);
TEST(testIsNumber); TEST(testIsNumber);
TEST(testIsPowerOfTwo); TEST(testIsPowerOfTwo);
TEST(testMyround);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -239,3 +241,12 @@ void TestUtilities::testIsPowerOfTwo()
} }
UASSERT(is_power_of_two((u32)-1) == false); 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);
}

View File

@ -288,7 +288,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
*/ */
inline s32 myround(f32 f) inline s32 myround(f32 f)
{ {
return floor(f + 0.5); return (s32)(f < 0.f ? (f - 0.5f) : (f + 0.5f));
} }
/* /*