| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 CHECK_EQ(40000e-328, StrtodChar("30000", -328)); | 193 CHECK_EQ(40000e-328, StrtodChar("30000", -328)); |
| 194 CHECK_EQ(0.0, StrtodChar("10000", -329)); | 194 CHECK_EQ(0.0, StrtodChar("10000", -329)); |
| 195 CHECK_EQ(0.0, StrtodChar("90000", -329)); | 195 CHECK_EQ(0.0, StrtodChar("90000", -329)); |
| 196 CHECK_EQ(0.0, StrtodChar("000000001", -325)); | 196 CHECK_EQ(0.0, StrtodChar("000000001", -325)); |
| 197 CHECK_EQ(0.0, StrtodChar("000000001", -325)); | 197 CHECK_EQ(0.0, StrtodChar("000000001", -325)); |
| 198 CHECK_EQ(0.0, StrtodChar("0000000020000", -328)); | 198 CHECK_EQ(0.0, StrtodChar("0000000020000", -328)); |
| 199 CHECK_EQ(40000e-328, StrtodChar("00000030000", -328)); | 199 CHECK_EQ(40000e-328, StrtodChar("00000030000", -328)); |
| 200 CHECK_EQ(0.0, StrtodChar("0000000010000", -329)); | 200 CHECK_EQ(0.0, StrtodChar("0000000010000", -329)); |
| 201 CHECK_EQ(0.0, StrtodChar("0000000090000", -329)); | 201 CHECK_EQ(0.0, StrtodChar("0000000090000", -329)); |
| 202 | 202 |
| 203 // It would be more readable to put the literals (and not | 203 // It would be more readable to put the literals (and not V8_INFINITY) on the |
| 204 // std::numeric_limits<double>::infinity()) on the | |
| 205 // left side (i.e. CHECK_EQ(1e309, StrtodChar("1", 309))), but then Gcc | 204 // left side (i.e. CHECK_EQ(1e309, StrtodChar("1", 309))), but then Gcc |
| 206 // complains that the floating constant exceeds range of 'double'. | 205 // complains that the floating constant exceeds range of 'double'. |
| 207 CHECK_EQ(std::numeric_limits<double>::infinity(), StrtodChar("1", 309)); | 206 CHECK_EQ(V8_INFINITY, StrtodChar("1", 309)); |
| 208 CHECK_EQ(1e308, StrtodChar("1", 308)); | 207 CHECK_EQ(1e308, StrtodChar("1", 308)); |
| 209 CHECK_EQ(1234e305, StrtodChar("1234", 305)); | 208 CHECK_EQ(1234e305, StrtodChar("1234", 305)); |
| 210 CHECK_EQ(1234e304, StrtodChar("1234", 304)); | 209 CHECK_EQ(1234e304, StrtodChar("1234", 304)); |
| 211 CHECK_EQ(std::numeric_limits<double>::infinity(), StrtodChar("18", 307)); | 210 CHECK_EQ(V8_INFINITY, StrtodChar("18", 307)); |
| 212 CHECK_EQ(17e307, StrtodChar("17", 307)); | 211 CHECK_EQ(17e307, StrtodChar("17", 307)); |
| 213 CHECK_EQ(std::numeric_limits<double>::infinity(), StrtodChar("0000001", 309)); | 212 CHECK_EQ(V8_INFINITY, StrtodChar("0000001", 309)); |
| 214 CHECK_EQ(1e308, StrtodChar("00000001", 308)); | 213 CHECK_EQ(1e308, StrtodChar("00000001", 308)); |
| 215 CHECK_EQ(1234e305, StrtodChar("00000001234", 305)); | 214 CHECK_EQ(1234e305, StrtodChar("00000001234", 305)); |
| 216 CHECK_EQ(1234e304, StrtodChar("000000001234", 304)); | 215 CHECK_EQ(1234e304, StrtodChar("000000001234", 304)); |
| 217 CHECK_EQ(std::numeric_limits<double>::infinity(), | 216 CHECK_EQ(V8_INFINITY, StrtodChar("0000000018", 307)); |
| 218 StrtodChar("0000000018", 307)); | |
| 219 CHECK_EQ(17e307, StrtodChar("0000000017", 307)); | 217 CHECK_EQ(17e307, StrtodChar("0000000017", 307)); |
| 220 CHECK_EQ(std::numeric_limits<double>::infinity(), StrtodChar("1000000", 303)); | 218 CHECK_EQ(V8_INFINITY, StrtodChar("1000000", 303)); |
| 221 CHECK_EQ(1e308, StrtodChar("100000", 303)); | 219 CHECK_EQ(1e308, StrtodChar("100000", 303)); |
| 222 CHECK_EQ(1234e305, StrtodChar("123400000", 300)); | 220 CHECK_EQ(1234e305, StrtodChar("123400000", 300)); |
| 223 CHECK_EQ(1234e304, StrtodChar("123400000", 299)); | 221 CHECK_EQ(1234e304, StrtodChar("123400000", 299)); |
| 224 CHECK_EQ(std::numeric_limits<double>::infinity(), | 222 CHECK_EQ(V8_INFINITY, StrtodChar("180000000", 300)); |
| 225 StrtodChar("180000000", 300)); | |
| 226 CHECK_EQ(17e307, StrtodChar("170000000", 300)); | 223 CHECK_EQ(17e307, StrtodChar("170000000", 300)); |
| 227 CHECK_EQ(std::numeric_limits<double>::infinity(), | 224 CHECK_EQ(V8_INFINITY, StrtodChar("00000001000000", 303)); |
| 228 StrtodChar("00000001000000", 303)); | |
| 229 CHECK_EQ(1e308, StrtodChar("000000000000100000", 303)); | 225 CHECK_EQ(1e308, StrtodChar("000000000000100000", 303)); |
| 230 CHECK_EQ(1234e305, StrtodChar("00000000123400000", 300)); | 226 CHECK_EQ(1234e305, StrtodChar("00000000123400000", 300)); |
| 231 CHECK_EQ(1234e304, StrtodChar("0000000123400000", 299)); | 227 CHECK_EQ(1234e304, StrtodChar("0000000123400000", 299)); |
| 232 CHECK_EQ(std::numeric_limits<double>::infinity(), | 228 CHECK_EQ(V8_INFINITY, StrtodChar("00000000180000000", 300)); |
| 233 StrtodChar("00000000180000000", 300)); | |
| 234 CHECK_EQ(17e307, StrtodChar("00000000170000000", 300)); | 229 CHECK_EQ(17e307, StrtodChar("00000000170000000", 300)); |
| 235 CHECK_EQ(1.7976931348623157E+308, StrtodChar("17976931348623157", 292)); | 230 CHECK_EQ(1.7976931348623157E+308, StrtodChar("17976931348623157", 292)); |
| 236 CHECK_EQ(1.7976931348623158E+308, StrtodChar("17976931348623158", 292)); | 231 CHECK_EQ(1.7976931348623158E+308, StrtodChar("17976931348623158", 292)); |
| 237 CHECK_EQ(std::numeric_limits<double>::infinity(), | 232 CHECK_EQ(V8_INFINITY, StrtodChar("17976931348623159", 292)); |
| 238 StrtodChar("17976931348623159", 292)); | |
| 239 | 233 |
| 240 // The following number is the result of 89255.0/1e22. Both floating-point | 234 // The following number is the result of 89255.0/1e22. Both floating-point |
| 241 // numbers can be accurately represented with doubles. However on Linux,x86 | 235 // numbers can be accurately represented with doubles. However on Linux,x86 |
| 242 // the floating-point stack is set to 80bits and the double-rounding | 236 // the floating-point stack is set to 80bits and the double-rounding |
| 243 // introduces an error. | 237 // introduces an error. |
| 244 CHECK_EQ(89255e-22, StrtodChar("89255", -22)); | 238 CHECK_EQ(89255e-22, StrtodChar("89255", -22)); |
| 245 | 239 |
| 246 // Some random values. | 240 // Some random values. |
| 247 CHECK_EQ(358416272e-33, StrtodChar("358416272", -33)); | 241 CHECK_EQ(358416272e-33, StrtodChar("358416272", -33)); |
| 248 CHECK_EQ(104110013277974872254e-225, | 242 CHECK_EQ(104110013277974872254e-225, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 DiyFp upper_boundary; | 400 DiyFp upper_boundary; |
| 407 Bignum input_digits; | 401 Bignum input_digits; |
| 408 input_digits.AssignDecimalString(buffer); | 402 input_digits.AssignDecimalString(buffer); |
| 409 if (to_check == 0.0) { | 403 if (to_check == 0.0) { |
| 410 const double kMinDouble = 4e-324; | 404 const double kMinDouble = 4e-324; |
| 411 // Check that the buffer*10^exponent < (0 + kMinDouble)/2. | 405 // Check that the buffer*10^exponent < (0 + kMinDouble)/2. |
| 412 Double d(kMinDouble); | 406 Double d(kMinDouble); |
| 413 d.NormalizedBoundaries(&lower_boundary, &upper_boundary); | 407 d.NormalizedBoundaries(&lower_boundary, &upper_boundary); |
| 414 return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) <= 0; | 408 return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) <= 0; |
| 415 } | 409 } |
| 416 if (to_check == std::numeric_limits<double>::infinity()) { | 410 if (to_check == V8_INFINITY) { |
| 417 const double kMaxDouble = 1.7976931348623157e308; | 411 const double kMaxDouble = 1.7976931348623157e308; |
| 418 // Check that the buffer*10^exponent >= boundary between kMaxDouble and inf. | 412 // Check that the buffer*10^exponent >= boundary between kMaxDouble and inf. |
| 419 Double d(kMaxDouble); | 413 Double d(kMaxDouble); |
| 420 d.NormalizedBoundaries(&lower_boundary, &upper_boundary); | 414 d.NormalizedBoundaries(&lower_boundary, &upper_boundary); |
| 421 return CompareBignumToDiyFp(input_digits, exponent, upper_boundary) >= 0; | 415 return CompareBignumToDiyFp(input_digits, exponent, upper_boundary) >= 0; |
| 422 } | 416 } |
| 423 Double d(to_check); | 417 Double d(to_check); |
| 424 d.NormalizedBoundaries(&lower_boundary, &upper_boundary); | 418 d.NormalizedBoundaries(&lower_boundary, &upper_boundary); |
| 425 if ((d.Significand() & 1) == 0) { | 419 if ((d.Significand() & 1) == 0) { |
| 426 return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) >= 0 && | 420 return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) >= 0 && |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 buffer[pos++] = rng.NextInt(10) + '0'; | 471 buffer[pos++] = rng.NextInt(10) + '0'; |
| 478 } | 472 } |
| 479 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length; | 473 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length; |
| 480 buffer[pos] = '\0'; | 474 buffer[pos] = '\0'; |
| 481 Vector<const char> vector(buffer, pos); | 475 Vector<const char> vector(buffer, pos); |
| 482 double strtod_result = Strtod(vector, exponent); | 476 double strtod_result = Strtod(vector, exponent); |
| 483 CHECK(CheckDouble(vector, exponent, strtod_result)); | 477 CHECK(CheckDouble(vector, exponent, strtod_result)); |
| 484 } | 478 } |
| 485 } | 479 } |
| 486 } | 480 } |
| OLD | NEW |