Skip to content

Commit d496e04

Browse files
committed
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().
1 parent f587e6a commit d496e04

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

src/lib_json/json_value.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static inline bool InRange(double d, T min, U max) {
5656
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
5757
static inline double integerToDouble( Json::UInt64 value )
5858
{
59-
return static_cast<double>( UInt(value >> 32) ) * (UInt64(1)<<32) + UInt(value & 0xffffffff);
59+
return static_cast<double>( Int64(value/2) ) * 2.0 + Int64(value & 1);
6060
}
6161

6262
template<typename T>
@@ -878,7 +878,7 @@ Value::asFloat() const
878878
#if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
879879
return static_cast<float>( value_.uint_ );
880880
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
881-
return static_cast<float>( Int(value_.uint_/2) ) * 2 + Int(value_.uint_ & 1);
881+
return integerToDouble( value_.uint_ );
882882
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
883883
case realValue:
884884
return static_cast<float>( value_.real_ );

src/test_lib_json/main.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
// recognized in your jurisdiction.
44
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
55

6-
#include <limits>
7-
86
#include <json/config.h>
97
#include <json/json.h>
108
#include "jsontest.h"
119

1210
// Make numeric limits more convenient to talk about.
1311
// Assumes int type in 32 bits.
14-
#define kint32max std::numeric_limits<int>::max()
15-
#define kint32min std::numeric_limits<int>::min()
16-
#define kuint32max std::numeric_limits<unsigned int>::max()
17-
#define kint64max std::numeric_limits<Json::Int64>::max()
18-
#define kint64min std::numeric_limits<Json::Int64>::min()
19-
#define kuint64max std::numeric_limits<Json::UInt64>::max()
12+
#define kint32max Json::Value::maxInt
13+
#define kint32min Json::Value::minInt
14+
#define kuint32max Json::Value::maxUInt
15+
#define kint64max Json::Value::maxInt64
16+
#define kint64min Json::Value::minInt64
17+
#define kuint64max Json::Value::maxUInt64
2018

2119
static const double kdint64max = double(kint64max);
2220
static const float kfint64max = float(kint64max);
@@ -38,7 +36,7 @@ static inline double uint64ToDouble( Json::UInt64 value )
3836
#else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
3937
static inline double uint64ToDouble( Json::UInt64 value )
4038
{
41-
return static_cast<double>( Json::UInt(value >> 32) ) * (Json::UInt64(1)<<32) + Json::UInt(value & 0xffffffff);
39+
return static_cast<double>( Json::Int64(value/2) ) * 2.0 + Json::Int64(value & 1);
4240
}
4341
#endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION)
4442

0 commit comments

Comments
 (0)