| 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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 // Copied from v8.cc and adapted to make the function deterministic. | 428 // Copied from v8.cc and adapted to make the function deterministic. |
| 429 static uint32_t DeterministicRandom() { | 429 static uint32_t DeterministicRandom() { |
| 430 // Random number generator using George Marsaglia's MWC algorithm. | 430 // Random number generator using George Marsaglia's MWC algorithm. |
| 431 static uint32_t hi = 0; | 431 static uint32_t hi = 0; |
| 432 static uint32_t lo = 0; | 432 static uint32_t lo = 0; |
| 433 | 433 |
| 434 // Initialization values don't have any special meaning. (They are the result | 434 // Initialization values don't have any special meaning. (They are the result |
| 435 // of two calls to random().) | 435 // of two calls to rand().) |
| 436 if (hi == 0) hi = 0xbfe166e7; | 436 if (hi == 0) hi = 0xbfe166e7; |
| 437 if (lo == 0) lo = 0x64d1c3c9; | 437 if (lo == 0) lo = 0x64d1c3c9; |
| 438 | 438 |
| 439 // Mix the bits. | 439 // Mix the bits. |
| 440 hi = 36969 * (hi & 0xFFFF) + (hi >> 16); | 440 hi = 36969 * (hi & 0xFFFF) + (hi >> 16); |
| 441 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); | 441 lo = 18273 * (lo & 0xFFFF) + (lo >> 16); |
| 442 return (hi << 16) + (lo & 0xFFFF); | 442 return (hi << 16) + (lo & 0xFFFF); |
| 443 } | 443 } |
| 444 | 444 |
| 445 | 445 |
| 446 static const int kBufferSize = 1024; | 446 static const int kBufferSize = 1024; |
| 447 static const int kShortStrtodRandomCount = 2; | 447 static const int kShortStrtodRandomCount = 2; |
| 448 static const int kLargeStrtodRandomCount = 2; | 448 static const int kLargeStrtodRandomCount = 2; |
| 449 | 449 |
| 450 TEST(RandomStrtod) { | 450 TEST(RandomStrtod) { |
| 451 srand(time(NULL)); |
| 451 char buffer[kBufferSize]; | 452 char buffer[kBufferSize]; |
| 452 for (int length = 1; length < 15; length++) { | 453 for (int length = 1; length < 15; length++) { |
| 453 for (int i = 0; i < kShortStrtodRandomCount; ++i) { | 454 for (int i = 0; i < kShortStrtodRandomCount; ++i) { |
| 454 int pos = 0; | 455 int pos = 0; |
| 455 for (int j = 0; j < length; ++j) { | 456 for (int j = 0; j < length; ++j) { |
| 456 buffer[pos++] = random() % 10 + '0'; | 457 buffer[pos++] = rand() % 10 + '0'; |
| 457 } | 458 } |
| 458 int exponent = DeterministicRandom() % (25*2 + 1) - 25 - length; | 459 int exponent = DeterministicRandom() % (25*2 + 1) - 25 - length; |
| 459 buffer[pos] = '\0'; | 460 buffer[pos] = '\0'; |
| 460 Vector<const char> vector(buffer, pos); | 461 Vector<const char> vector(buffer, pos); |
| 461 double strtod_result = Strtod(vector, exponent); | 462 double strtod_result = Strtod(vector, exponent); |
| 462 CHECK(CheckDouble(vector, exponent, strtod_result)); | 463 CHECK(CheckDouble(vector, exponent, strtod_result)); |
| 463 } | 464 } |
| 464 } | 465 } |
| 465 for (int length = 15; length < 800; length += 2) { | 466 for (int length = 15; length < 800; length += 2) { |
| 466 for (int i = 0; i < kLargeStrtodRandomCount; ++i) { | 467 for (int i = 0; i < kLargeStrtodRandomCount; ++i) { |
| 467 int pos = 0; | 468 int pos = 0; |
| 468 for (int j = 0; j < length; ++j) { | 469 for (int j = 0; j < length; ++j) { |
| 469 buffer[pos++] = random() % 10 + '0'; | 470 buffer[pos++] = rand() % 10 + '0'; |
| 470 } | 471 } |
| 471 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length; | 472 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length; |
| 472 buffer[pos] = '\0'; | 473 buffer[pos] = '\0'; |
| 473 Vector<const char> vector(buffer, pos); | 474 Vector<const char> vector(buffer, pos); |
| 474 double strtod_result = Strtod(vector, exponent); | 475 double strtod_result = Strtod(vector, exponent); |
| 475 CHECK(CheckDouble(vector, exponent, strtod_result)); | 476 CHECK(CheckDouble(vector, exponent, strtod_result)); |
| 476 } | 477 } |
| 477 } | 478 } |
| 478 } | 479 } |
| OLD | NEW |