"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/unittest/strtodtest.cpp" between
rapidjson-1.0.2.tar.gz and rapidjson-1.1.0.tar.gz

About: RapidJSON is a fast JSON parser/generator for C++ with both SAX/DOM style API.

strtodtest.cpp  (rapidjson-1.0.2):strtodtest.cpp  (rapidjson-1.1.0)
skipping to change at line 19 skipping to change at line 19
// //
// Unless required by applicable law or agreed to in writing, software distribut ed // Unless required by applicable law or agreed to in writing, software distribut ed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the // CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License. // specific language governing permissions and limitations under the License.
#include "unittest.h" #include "unittest.h"
#include "rapidjson/internal/strtod.h" #include "rapidjson/internal/strtod.h"
#ifdef __clang__
RAPIDJSON_DIAG_PUSH
RAPIDJSON_DIAG_OFF(unreachable-code)
#endif
#define BIGINTEGER_LITERAL(s) BigInteger(s, sizeof(s) - 1) #define BIGINTEGER_LITERAL(s) BigInteger(s, sizeof(s) - 1)
using namespace rapidjson::internal; using namespace rapidjson::internal;
TEST(Strtod, CheckApproximationCase) { TEST(Strtod, CheckApproximationCase) {
static const int kSignificandSize = 52; static const int kSignificandSize = 52;
static const int kExponentBias = 0x3FF; static const int kExponentBias = 0x3FF;
static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x0000 0000); static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x0000 0000);
static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xF FFFFFFF); static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xF FFFFFFF);
static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x0000000 0); static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x0000000 0);
skipping to change at line 40 skipping to change at line 45
// http://www.exploringbinary.com/using-integers-to-check-a-floating-point-a pproximation/ // http://www.exploringbinary.com/using-integers-to-check-a-floating-point-a pproximation/
// Let b = 0x1.465a72e467d88p-149 // Let b = 0x1.465a72e467d88p-149
// = 5741268244528520 x 2^-201 // = 5741268244528520 x 2^-201
union { union {
double d; double d;
uint64_t u; uint64_t u;
}u; }u;
u.u = 0x465a72e467d88 | ((static_cast<uint64_t>(-149 + kExponentBias)) << kS ignificandSize); u.u = 0x465a72e467d88 | ((static_cast<uint64_t>(-149 + kExponentBias)) << kS ignificandSize);
const double b = u.d; const double b = u.d;
const uint64_t bInt = (u.u & kSignificandMask) | kHiddenBit; const uint64_t bInt = (u.u & kSignificandMask) | kHiddenBit;
const int bExp = ((u.u & kExponentMask) >> kSignificandSize) - kExponentBias - kSignificandSize; const int bExp = static_cast<int>(((u.u & kExponentMask) >> kSignificandSize ) - kExponentBias - kSignificandSize);
EXPECT_DOUBLE_EQ(1.7864e-45, b); EXPECT_DOUBLE_EQ(1.7864e-45, b);
EXPECT_EQ(RAPIDJSON_UINT64_C2(0x001465a7, 0x2e467d88), bInt); EXPECT_EQ(RAPIDJSON_UINT64_C2(0x001465a7, 0x2e467d88), bInt);
EXPECT_EQ(-201, bExp); EXPECT_EQ(-201, bExp);
// Let d = 17864 x 10-49 // Let d = 17864 x 10-49
const char dInt[] = "17864"; const char dInt[] = "17864";
const int dExp = -49; const int dExp = -49;
// Let h = 2^(bExp-1) // Let h = 2^(bExp-1)
const int hExp = bExp - 1; const int hExp = bExp - 1;
skipping to change at line 102 skipping to change at line 107
hS_Exp2 -= common_Exp2; hS_Exp2 -= common_Exp2;
EXPECT_EQ(153, dS_Exp2); EXPECT_EQ(153, dS_Exp2);
EXPECT_EQ(0, dS_Exp5); EXPECT_EQ(0, dS_Exp5);
EXPECT_EQ(1, bS_Exp2); EXPECT_EQ(1, bS_Exp2);
EXPECT_EQ(49, bS_Exp5); EXPECT_EQ(49, bS_Exp5);
EXPECT_EQ(0, hS_Exp2); EXPECT_EQ(0, hS_Exp2);
EXPECT_EQ(49, hS_Exp5); EXPECT_EQ(49, hS_Exp5);
BigInteger dS = BIGINTEGER_LITERAL(dInt); BigInteger dS = BIGINTEGER_LITERAL(dInt);
dS.MultiplyPow5(dS_Exp5) <<= dS_Exp2; dS.MultiplyPow5(static_cast<unsigned>(dS_Exp5)) <<= static_cast<size_t>(dS_E xp2);
BigInteger bS(bInt); BigInteger bS(bInt);
bS.MultiplyPow5(bS_Exp5) <<= bS_Exp2; bS.MultiplyPow5(static_cast<unsigned>(bS_Exp5)) <<= static_cast<size_t>(bS_E xp2);
BigInteger hS(1); BigInteger hS(1);
hS.MultiplyPow5(hS_Exp5) <<= hS_Exp2; hS.MultiplyPow5(static_cast<unsigned>(hS_Exp5)) <<= static_cast<size_t>(hS_E xp2);
EXPECT_TRUE(BIGINTEGER_LITERAL("20397082225999413852180176446596624893073108 5529088") == dS); EXPECT_TRUE(BIGINTEGER_LITERAL("20397082225999413852180176446596624893073108 5529088") == dS);
EXPECT_TRUE(BIGINTEGER_LITERAL("20397082225999412230521556921303272247314453 1250000") == bS); EXPECT_TRUE(BIGINTEGER_LITERAL("20397082225999412230521556921303272247314453 1250000") == bS);
EXPECT_TRUE(BIGINTEGER_LITERAL("17763568394002504646778106689453125") == hS) ; EXPECT_TRUE(BIGINTEGER_LITERAL("17763568394002504646778106689453125") == hS) ;
EXPECT_EQ(1, dS.Compare(bS)); EXPECT_EQ(1, dS.Compare(bS));
BigInteger delta(0); BigInteger delta(0);
EXPECT_FALSE(dS.Difference(bS, &delta)); EXPECT_FALSE(dS.Difference(bS, &delta));
EXPECT_TRUE(BIGINTEGER_LITERAL("16216586195252933526457586554279088") == del ta); EXPECT_TRUE(BIGINTEGER_LITERAL("16216586195252933526457586554279088") == del ta);
EXPECT_TRUE(bS.Difference(dS, &delta)); EXPECT_TRUE(bS.Difference(dS, &delta));
EXPECT_TRUE(BIGINTEGER_LITERAL("16216586195252933526457586554279088") == del ta); EXPECT_TRUE(BIGINTEGER_LITERAL("16216586195252933526457586554279088") == del ta);
EXPECT_EQ(-1, delta.Compare(hS)); EXPECT_EQ(-1, delta.Compare(hS));
} }
#ifdef __clang__
RAPIDJSON_DIAG_POP
#endif
 End of changes. 6 change blocks. 
4 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)