Log Message
Decimal constructor with 99999999999999999 loses last digit https://bugs.webkit.org/show_bug.cgi?id=91579
Reviewed by Kent Tamura. Source/WebCore: This patch changes maximum coefficient value handling in Decimal::EncodedData constructor not to lose the last digit. It was used ">=" operator for comparison instead of ">" operator. Tests: WebKit/chromium/tests/DecimalTest.cpp * platform/Decimal.cpp: (WebCore::Decimal::EncodedData::EncodedData): Replace ">=" to ">" for not getting rid of the last digit for maximum coefficient value. Source/WebKit/chromium: This patch adds test cases for Decimal::EncodedData constructors for testing edge cases in addition to common cases which they aren't covered by other test cases. * tests/DecimalTest.cpp: (EXPECT_DECIMAL_ENCODED_DATA_EQ): Introduce a new macro for ease of writing test cases for verifying components of Decimal::EncodedData. (TEST_F): Added a new test entry DecimalTest.Constructor.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (122921 => 122922)
--- trunk/Source/WebCore/ChangeLog 2012-07-18 06:31:53 UTC (rev 122921)
+++ trunk/Source/WebCore/ChangeLog 2012-07-18 06:50:25 UTC (rev 122922)
@@ -1,3 +1,20 @@
+2012-07-17 Yoshifumi Inoue <[email protected]>
+
+ Decimal constructor with 99999999999999999 loses last digit
+ https://bugs.webkit.org/show_bug.cgi?id=91579
+
+ Reviewed by Kent Tamura.
+
+ This patch changes maximum coefficient value handling in Decimal::EncodedData
+ constructor not to lose the last digit. It was used ">=" operator for
+ comparison instead of ">" operator.
+
+ Tests: WebKit/chromium/tests/DecimalTest.cpp
+
+ * platform/Decimal.cpp:
+ (WebCore::Decimal::EncodedData::EncodedData): Replace ">=" to ">" for
+ not getting rid of the last digit for maximum coefficient value.
+
2012-07-17 Ilya Tikhonovsky <[email protected]>
Unreviewed Web Inspector: followup fix for r122920.
Modified: trunk/Source/WebCore/platform/Decimal.cpp (122921 => 122922)
--- trunk/Source/WebCore/platform/Decimal.cpp 2012-07-18 06:31:53 UTC (rev 122921)
+++ trunk/Source/WebCore/platform/Decimal.cpp 2012-07-18 06:50:25 UTC (rev 122922)
@@ -246,7 +246,7 @@
, m_sign(sign)
{
if (exponent >= ExponentMin && exponent <= ExponentMax) {
- while (coefficient >= MaxCoefficient) {
+ while (coefficient > MaxCoefficient) {
coefficient /= 10;
++exponent;
}
Modified: trunk/Source/WebKit/chromium/ChangeLog (122921 => 122922)
--- trunk/Source/WebKit/chromium/ChangeLog 2012-07-18 06:31:53 UTC (rev 122921)
+++ trunk/Source/WebKit/chromium/ChangeLog 2012-07-18 06:50:25 UTC (rev 122922)
@@ -1,5 +1,21 @@
2012-07-17 Yoshifumi Inoue <[email protected]>
+ Decimal constructor with 99999999999999999 loses last digit
+ https://bugs.webkit.org/show_bug.cgi?id=91579
+
+ Reviewed by Kent Tamura.
+
+ This patch adds test cases for Decimal::EncodedData constructors for
+ testing edge cases in addition to common cases which they aren't
+ covered by other test cases.
+
+ * tests/DecimalTest.cpp:
+ (EXPECT_DECIMAL_ENCODED_DATA_EQ): Introduce a new macro for ease of
+ writing test cases for verifying components of Decimal::EncodedData.
+ (TEST_F): Added a new test entry DecimalTest.Constructor.
+
+2012-07-17 Yoshifumi Inoue <[email protected]>
+
Test cases in DecimalTest should use EXPECT_STREQ for ease of debugging test case
https://bugs.webkit.org/show_bug.cgi?id=91572
Modified: trunk/Source/WebKit/chromium/tests/DecimalTest.cpp (122921 => 122922)
--- trunk/Source/WebKit/chromium/tests/DecimalTest.cpp 2012-07-18 06:31:53 UTC (rev 122921)
+++ trunk/Source/WebKit/chromium/tests/DecimalTest.cpp 2012-07-18 06:50:25 UTC (rev 122922)
@@ -112,6 +112,12 @@
}
};
+// FIXME: We should use expectedSign without "Decimal::", however, g++ causes undefined references for DecimalTest::Positive and Negative.
+#define EXPECT_DECIMAL_ENCODED_DATA_EQ(expectedCoefficient, expectedExponent, expectedSign, decimal) \
+ EXPECT_EQ((expectedCoefficient), (decimal).value().coefficient()); \
+ EXPECT_EQ((expectedExponent), (decimal).value().exponent()); \
+ EXPECT_EQ(Decimal::expectedSign, (decimal).value().sign());
+
#define EXPECT_DECIMAL_STREQ(expected, decimal) EXPECT_STREQ((expected), (decimal).toString().ascii().data())
TEST_F(DecimalTest, Abs)
@@ -447,6 +453,28 @@
EXPECT_TRUE(NaN >= NaN);
}
+TEST_F(DecimalTest, Constructor)
+{
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(0u, 0, Positive, encode(0, 0, Positive));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(0u, 0, Negative, encode(0, 0, Negative));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(1u, 0, Positive, encode(1, 0, Positive));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(1u, 0, Negative, encode(1, 0, Negative));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(1u, 1022, Positive, encode(1, 1022, Positive));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(1u, 1022, Negative, encode(1, 1022, Negative));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(1u, 1023, Positive, encode(1, 1023, Positive));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(1u, 1023, Negative, encode(1, 1023, Negative));
+ EXPECT_TRUE(encode(1, 2000, Positive).isInfinity());
+ EXPECT_TRUE(encode(1, 2000, Negative).isInfinity());
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(0u, 0, Positive, encode(1, -2000, Positive));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(0u, 0, Negative, encode(1, -2000, Negative));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(UINT64_C(99999999999999998), 0, Positive, encode(UINT64_C(99999999999999998), 0, Positive));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(UINT64_C(99999999999999998), 0, Negative, encode(UINT64_C(99999999999999998), 0, Negative));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(UINT64_C(99999999999999999), 0, Positive, encode(UINT64_C(99999999999999999), 0, Positive));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(UINT64_C(99999999999999999), 0, Negative, encode(UINT64_C(99999999999999999), 0, Negative));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(UINT64_C(10000000000000000), 1, Positive, encode(UINT64_C(100000000000000000), 0, Positive));
+ EXPECT_DECIMAL_ENCODED_DATA_EQ(UINT64_C(10000000000000000), 1, Negative, encode(UINT64_C(100000000000000000), 0, Negative));
+}
+
TEST_F(DecimalTest, Division)
{
EXPECT_EQ(encode(0, 0, Positive), Decimal(0) / Decimal(1));
_______________________________________________ webkit-changes mailing list [email protected] http://lists.webkit.org/mailman/listinfo/webkit-changes
