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 | 2 |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 | 4 |
5 #include "v8.h" | 5 #include "v8.h" |
6 | 6 |
7 #include "bignum.h" | 7 #include "bignum.h" |
8 #include "cctest.h" | 8 #include "cctest.h" |
9 #include "diy-fp.h" | 9 #include "diy-fp.h" |
10 #include "double.h" | 10 #include "double.h" |
11 #include "strtod.h" | 11 #include "strtod.h" |
12 | 12 |
13 using namespace v8::internal; | 13 using namespace v8::internal; |
14 | 14 |
15 static Vector<const char> StringToVector(const char* str) { | 15 static Vector<const char> StringToVector(const char* str) { |
16 return Vector<const char>(str, StrLength(str)); | 16 return Vector<const char>(str, StrLength(str)); |
17 } | 17 } |
18 | 18 |
19 | 19 |
20 static double StrtodChar(const char* str, int exponent) { | 20 static double StrtodChar(const char* str, int exponent) { |
21 return Strtod(StringToVector(str), exponent); | 21 return Strtod(StringToVector(str), exponent); |
22 } | 22 } |
23 | 23 |
24 | 24 |
25 TEST(Strtod) { | 25 TEST(Strtod) { |
| 26 v8::V8::Initialize(); |
| 27 |
26 Vector<const char> vector; | 28 Vector<const char> vector; |
27 | 29 |
28 vector = StringToVector("0"); | 30 vector = StringToVector("0"); |
29 CHECK_EQ(0.0, Strtod(vector, 1)); | 31 CHECK_EQ(0.0, Strtod(vector, 1)); |
30 CHECK_EQ(0.0, Strtod(vector, 2)); | 32 CHECK_EQ(0.0, Strtod(vector, 2)); |
31 CHECK_EQ(0.0, Strtod(vector, -2)); | 33 CHECK_EQ(0.0, Strtod(vector, -2)); |
32 CHECK_EQ(0.0, Strtod(vector, -999)); | 34 CHECK_EQ(0.0, Strtod(vector, -999)); |
33 CHECK_EQ(0.0, Strtod(vector, +999)); | 35 CHECK_EQ(0.0, Strtod(vector, +999)); |
34 | 36 |
35 vector = StringToVector("1"); | 37 vector = StringToVector("1"); |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 buffer[pos++] = random() % 10 + '0'; | 446 buffer[pos++] = random() % 10 + '0'; |
445 } | 447 } |
446 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length; | 448 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length; |
447 buffer[pos] = '\0'; | 449 buffer[pos] = '\0'; |
448 Vector<const char> vector(buffer, pos); | 450 Vector<const char> vector(buffer, pos); |
449 double strtod_result = Strtod(vector, exponent); | 451 double strtod_result = Strtod(vector, exponent); |
450 CHECK(CheckDouble(vector, exponent, strtod_result)); | 452 CHECK(CheckDouble(vector, exponent, strtod_result)); |
451 } | 453 } |
452 } | 454 } |
453 } | 455 } |
OLD | NEW |