From d496e044b106dd2fd3f6d6fb9ddf6ae48637a525 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Fri, 27 May 2011 08:12:41 +0000 Subject: [PATCH] Fixed unit tests execution on MSVC 6 by removing usage of std::numeric_limits. It was returning 0 value in some max cases. Fixed Value::asFloat() to use integerToDouble(). --- src/lib_json/json_value.cpp | 4 ++-- src/test_lib_json/main.cpp | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 0149abd..b629987 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -56,7 +56,7 @@ static inline bool InRange(double d, T min, U max) { #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) static inline double integerToDouble( Json::UInt64 value ) { - return static_cast( UInt(value >> 32) ) * (UInt64(1)<<32) + UInt(value & 0xffffffff); + return static_cast( Int64(value/2) ) * 2.0 + Int64(value & 1); } template @@ -878,7 +878,7 @@ Value::asFloat() const #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) return static_cast( value_.uint_ ); #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) - return static_cast( Int(value_.uint_/2) ) * 2 + Int(value_.uint_ & 1); + return integerToDouble( value_.uint_ ); #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) case realValue: return static_cast( value_.real_ ); diff --git a/src/test_lib_json/main.cpp b/src/test_lib_json/main.cpp index 773bf10..c6ab619 100644 --- a/src/test_lib_json/main.cpp +++ b/src/test_lib_json/main.cpp @@ -3,20 +3,18 @@ // recognized in your jurisdiction. // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE -#include - #include #include #include "jsontest.h" // Make numeric limits more convenient to talk about. // Assumes int type in 32 bits. -#define kint32max std::numeric_limits::max() -#define kint32min std::numeric_limits::min() -#define kuint32max std::numeric_limits::max() -#define kint64max std::numeric_limits::max() -#define kint64min std::numeric_limits::min() -#define kuint64max std::numeric_limits::max() +#define kint32max Json::Value::maxInt +#define kint32min Json::Value::minInt +#define kuint32max Json::Value::maxUInt +#define kint64max Json::Value::maxInt64 +#define kint64min Json::Value::minInt64 +#define kuint64max Json::Value::maxUInt64 static const double kdint64max = double(kint64max); static const float kfint64max = float(kint64max); @@ -38,7 +36,7 @@ static inline double uint64ToDouble( Json::UInt64 value ) #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) static inline double uint64ToDouble( Json::UInt64 value ) { - return static_cast( Json::UInt(value >> 32) ) * (Json::UInt64(1)<<32) + Json::UInt(value & 0xffffffff); + return static_cast( Json::Int64(value/2) ) * 2.0 + Json::Int64(value & 1); } #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)