Revision: 5594
Author: [email protected]
Date: Wed Oct  6 01:33:52 2010
Log: During StringToDouble negative exponents may be less than -999 with a result that is not 0.0.
Review URL: http://codereview.chromium.org/3564011
http://code.google.com/p/v8/source/detail?r=5594

Modified:
 /branches/bleeding_edge/src/conversions.cc
 /branches/bleeding_edge/test/cctest/test-conversions.cc

=======================================
--- /branches/bleeding_edge/src/conversions.cc  Mon Sep 20 02:18:00 2010
+++ /branches/bleeding_edge/src/conversions.cc  Wed Oct  6 01:33:52 2010
@@ -665,9 +665,15 @@
       buffer[buffer_pos++] = '-';
       exponent = -exponent;
     }
- if (exponent > 999) exponent = 999; // Result will be Infinity or 0 or -0.
-
-    const int exp_digits = 3;
+
+    // The minimal/maximal double is +/-1.7e-308. Given that
+    // the buffer contains at most 773 (kMaxSignificantDigits + 1) the
+    // minimal possible exponent is hence -(308 + 773)=-1081.
+ // Since leading zeros are removed the maximal exponent cannot exceed 308. + // If the following test triggers the result will be +/-infinity or +/-0.
+    if (exponent > 9999) exponent = 9999;
+
+    const int exp_digits = 4;
     for (int i = 0; i < exp_digits; i++) {
       buffer[buffer_pos + exp_digits - 1 - i] = '0' + exponent % 10;
       exponent /= 10;
=======================================
--- /branches/bleeding_edge/test/cctest/test-conversions.cc Thu Mar 25 07:39:39 2010 +++ /branches/bleeding_edge/test/cctest/test-conversions.cc Wed Oct 6 01:33:52 2010
@@ -167,6 +167,38 @@

   CHECK_EQ(gay_strtod(num, NULL), StringToDouble(num, NO_FLAGS));
 }
+
+TEST(MinimumExponent) {
+  // Same test but with different point-position.
+  char num[] =
+  "445014771701440202508199667279499186358524265859260511351695091"
+  "228726223124931264069530541271189424317838013700808305231545782"
+  "515453032382772695923684574304409936197089118747150815050941806"
+  "048037511737832041185193533879641611520514874130831632725201246"
+  "060231058690536206311752656217652146466431814205051640436322226"
+  "680064743260560117135282915796422274554896821334728738317548403"
+  "413978098469341510556195293821919814730032341053661708792231510"
+  "873354131880491105553390278848567812190177545006298062245710295"
+  "816371174594568773301103242116891776567137054973871082078224775"
+  "842509670618916870627821633352993761380751142008862499795052791"
+  "018709663463944015644907297315659352441231715398102212132212018"
+  "470035807616260163568645811358486831521563686919762403704226016"
+  "998291015625000000000000000000000000000000000e-1108";
+
+  CHECK_EQ(gay_strtod(num, NULL), StringToDouble(num, NO_FLAGS));
+
+  // Changes the result of strtod (at least in glibc implementation).
+  num[sizeof(num) - 8] = '1';
+
+  CHECK_EQ(gay_strtod(num, NULL), StringToDouble(num, NO_FLAGS));
+}
+
+
+TEST(MaximumExponent) {
+  char num[] = "0.16e309";
+
+  CHECK_EQ(gay_strtod(num, NULL), StringToDouble(num, NO_FLAGS));
+}


 TEST(ExponentNumberStr) {

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to