Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: Source/platform/DecimalTest.cpp

Issue 977593004: Avoid uint64_t overflow in Decimal::operator/() and fix Decimal::ceil() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-03-04T15:05:41 Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/platform/Decimal.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 EXPECT_EQ(Decimal(0), encode(1, -10, Negative).ceil()); 235 EXPECT_EQ(Decimal(0), encode(1, -10, Negative).ceil());
236 EXPECT_EQ(Decimal(-1), encode(11, -1, Negative).ceil()); 236 EXPECT_EQ(Decimal(-1), encode(11, -1, Negative).ceil());
237 EXPECT_EQ(Decimal(-1), encode(13, -1, Negative).ceil()); 237 EXPECT_EQ(Decimal(-1), encode(13, -1, Negative).ceil());
238 EXPECT_EQ(Decimal(-1), encode(15, -1, Negative).ceil()); 238 EXPECT_EQ(Decimal(-1), encode(15, -1, Negative).ceil());
239 EXPECT_EQ(Decimal(-1), encode(19, -1, Negative).ceil()); 239 EXPECT_EQ(Decimal(-1), encode(19, -1, Negative).ceil());
240 EXPECT_EQ(Decimal(-1), encode(151, -2, Negative).ceil()); 240 EXPECT_EQ(Decimal(-1), encode(151, -2, Negative).ceil());
241 EXPECT_EQ(Decimal(-1), encode(101, -2, Negative).ceil()); 241 EXPECT_EQ(Decimal(-1), encode(101, -2, Negative).ceil());
242 EXPECT_EQ(Decimal(0), encode(199, -3, Negative).ceil()); 242 EXPECT_EQ(Decimal(0), encode(199, -3, Negative).ceil());
243 EXPECT_EQ(Decimal(-1), encode(199, -2, Negative).ceil()); 243 EXPECT_EQ(Decimal(-1), encode(199, -2, Negative).ceil());
244 EXPECT_EQ(Decimal(-2), encode(209, -2, Negative).ceil()); 244 EXPECT_EQ(Decimal(-2), encode(209, -2, Negative).ceil());
245 EXPECT_EQ(Decimal(1), encode(UINT64_C(123456789012345678), -18, Positive).ce il());
245 } 246 }
246 247
247 TEST_F(DecimalTest, CeilingBigExponent) 248 TEST_F(DecimalTest, CeilingBigExponent)
248 { 249 {
249 EXPECT_EQ(encode(1, 1000, Positive), encode(1, 1000, Positive).ceil()); 250 EXPECT_EQ(encode(1, 1000, Positive), encode(1, 1000, Positive).ceil());
250 EXPECT_EQ(encode(1, 1000, Negative), encode(1, 1000, Negative).ceil()); 251 EXPECT_EQ(encode(1, 1000, Negative), encode(1, 1000, Negative).ceil());
251 } 252 }
252 253
253 TEST_F(DecimalTest, CeilingSmallExponent) 254 TEST_F(DecimalTest, CeilingSmallExponent)
254 { 255 {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 EXPECT_DECIMAL_ENCODED_DATA_EQ(UINT64_C(100000000000000000), 0, Negative, en code(UINT64_C(100000000000000000), 0, Negative)); 487 EXPECT_DECIMAL_ENCODED_DATA_EQ(UINT64_C(100000000000000000), 0, Negative, en code(UINT64_C(100000000000000000), 0, Negative));
487 } 488 }
488 489
489 TEST_F(DecimalTest, Division) 490 TEST_F(DecimalTest, Division)
490 { 491 {
491 EXPECT_EQ(encode(0, 0, Positive), Decimal(0) / Decimal(1)); 492 EXPECT_EQ(encode(0, 0, Positive), Decimal(0) / Decimal(1));
492 EXPECT_EQ(encode(2, 0, Negative), Decimal(2) / Decimal(-1)); 493 EXPECT_EQ(encode(2, 0, Negative), Decimal(2) / Decimal(-1));
493 EXPECT_EQ(encode(5, -1, Negative), Decimal(-1) / Decimal(2)); 494 EXPECT_EQ(encode(5, -1, Negative), Decimal(-1) / Decimal(2));
494 EXPECT_EQ(encode(99, 0, Positive), Decimal(99) / Decimal(1)); 495 EXPECT_EQ(encode(99, 0, Positive), Decimal(99) / Decimal(1));
495 EXPECT_EQ(Decimal(1), Decimal(-50) / Decimal(-50)); 496 EXPECT_EQ(Decimal(1), Decimal(-50) / Decimal(-50));
496 EXPECT_EQ(encode(UINT64_C(33333333333333333), -17, Positive), Decimal(1) / D ecimal(3)); 497 EXPECT_EQ(encode(UINT64_C(333333333333333333), -18, Positive), Decimal(1) / Decimal(3));
497 EXPECT_EQ(encode(UINT64_C(12345678901234), -1, Positive), encode(UINT64_C(12 345678901234), 0, Positive) / Decimal(10)); 498 EXPECT_EQ(encode(UINT64_C(12345678901234), -1, Positive), encode(UINT64_C(12 345678901234), 0, Positive) / Decimal(10));
499 EXPECT_EQ(encode(UINT64_C(500005000050000500), -18, Positive), Decimal(50000 ) / Decimal(99999));
498 } 500 }
499 501
500 TEST_F(DecimalTest, DivisionBigExponent) 502 TEST_F(DecimalTest, DivisionBigExponent)
501 { 503 {
502 EXPECT_EQ(encode(1, 1022, Positive), encode(1, 1022, Positive) / encode(1, 0 , Positive)); 504 EXPECT_EQ(encode(1, 1022, Positive), encode(1, 1022, Positive) / encode(1, 0 , Positive));
503 EXPECT_EQ(encode(1, 0, Positive), encode(1, 1022, Positive) / encode(1, 1022 , Positive)); 505 EXPECT_EQ(encode(1, 0, Positive), encode(1, 1022, Positive) / encode(1, 1022 , Positive));
504 EXPECT_EQ(Decimal::infinity(Positive), encode(1, 1022, Positive) / encode(1, -1000, Positive)); 506 EXPECT_EQ(Decimal::infinity(Positive), encode(1, 1022, Positive) / encode(1, -1000, Positive));
505 } 507 }
506 508
507 TEST_F(DecimalTest, DivisionSmallExponent) 509 TEST_F(DecimalTest, DivisionSmallExponent)
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 EXPECT_DECIMAL_STREQ("0.001", encode(UINT64_C(99999999999999999), -20, Posit ive)); 1116 EXPECT_DECIMAL_STREQ("0.001", encode(UINT64_C(99999999999999999), -20, Posit ive));
1115 EXPECT_DECIMAL_STREQ("1e-83", encode(UINT64_C(99999999999999999), -100, Posi tive)); 1117 EXPECT_DECIMAL_STREQ("1e-83", encode(UINT64_C(99999999999999999), -100, Posi tive));
1116 } 1118 }
1117 1119
1118 TEST_F(DecimalTest, ToStringSpecialValues) 1120 TEST_F(DecimalTest, ToStringSpecialValues)
1119 { 1121 {
1120 EXPECT_DECIMAL_STREQ("Infinity", Decimal::infinity(Positive)); 1122 EXPECT_DECIMAL_STREQ("Infinity", Decimal::infinity(Positive));
1121 EXPECT_DECIMAL_STREQ("-Infinity", Decimal::infinity(Negative)); 1123 EXPECT_DECIMAL_STREQ("-Infinity", Decimal::infinity(Negative));
1122 EXPECT_DECIMAL_STREQ("NaN", Decimal::nan()); 1124 EXPECT_DECIMAL_STREQ("NaN", Decimal::nan());
1123 } 1125 }
OLDNEW
« no previous file with comments | « Source/platform/Decimal.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698