| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 TEST(NonStrDecimalLiteral) { | 124 TEST(NonStrDecimalLiteral) { |
| 125 UnicodeCache uc; | 125 UnicodeCache uc; |
| 126 CHECK(std::isnan(StringToDouble(&uc, " ", NO_FLAGS, OS::nan_value()))); | 126 CHECK(std::isnan(StringToDouble(&uc, " ", NO_FLAGS, OS::nan_value()))); |
| 127 CHECK(std::isnan(StringToDouble(&uc, "", NO_FLAGS, OS::nan_value()))); | 127 CHECK(std::isnan(StringToDouble(&uc, "", NO_FLAGS, OS::nan_value()))); |
| 128 CHECK(std::isnan(StringToDouble(&uc, " ", NO_FLAGS, OS::nan_value()))); | 128 CHECK(std::isnan(StringToDouble(&uc, " ", NO_FLAGS, OS::nan_value()))); |
| 129 CHECK_EQ(0.0, StringToDouble(&uc, "", NO_FLAGS)); | 129 CHECK_EQ(0.0, StringToDouble(&uc, "", NO_FLAGS)); |
| 130 CHECK_EQ(0.0, StringToDouble(&uc, " ", NO_FLAGS)); | 130 CHECK_EQ(0.0, StringToDouble(&uc, " ", NO_FLAGS)); |
| 131 } | 131 } |
| 132 | 132 |
| 133 |
| 133 TEST(IntegerStrLiteral) { | 134 TEST(IntegerStrLiteral) { |
| 134 UnicodeCache uc; | 135 UnicodeCache uc; |
| 135 CHECK_EQ(0.0, StringToDouble(&uc, "0.0", NO_FLAGS)); | 136 CHECK_EQ(0.0, StringToDouble(&uc, "0.0", NO_FLAGS)); |
| 136 CHECK_EQ(0.0, StringToDouble(&uc, "0", NO_FLAGS)); | 137 CHECK_EQ(0.0, StringToDouble(&uc, "0", NO_FLAGS)); |
| 137 CHECK_EQ(0.0, StringToDouble(&uc, "00", NO_FLAGS)); | 138 CHECK_EQ(0.0, StringToDouble(&uc, "00", NO_FLAGS)); |
| 138 CHECK_EQ(0.0, StringToDouble(&uc, "000", NO_FLAGS)); | 139 CHECK_EQ(0.0, StringToDouble(&uc, "000", NO_FLAGS)); |
| 139 CHECK_EQ(1.0, StringToDouble(&uc, "1", NO_FLAGS)); | 140 CHECK_EQ(1.0, StringToDouble(&uc, "1", NO_FLAGS)); |
| 140 CHECK_EQ(-1.0, StringToDouble(&uc, "-1", NO_FLAGS)); | 141 CHECK_EQ(-1.0, StringToDouble(&uc, "-1", NO_FLAGS)); |
| 141 CHECK_EQ(-1.0, StringToDouble(&uc, " -1 ", NO_FLAGS)); | 142 CHECK_EQ(-1.0, StringToDouble(&uc, " -1 ", NO_FLAGS)); |
| 142 CHECK_EQ(1.0, StringToDouble(&uc, " +1 ", NO_FLAGS)); | 143 CHECK_EQ(1.0, StringToDouble(&uc, " +1 ", NO_FLAGS)); |
| 143 CHECK(std::isnan(StringToDouble(&uc, " - 1 ", NO_FLAGS))); | 144 CHECK(std::isnan(StringToDouble(&uc, " - 1 ", NO_FLAGS))); |
| 144 CHECK(std::isnan(StringToDouble(&uc, " + 1 ", NO_FLAGS))); | 145 CHECK(std::isnan(StringToDouble(&uc, " + 1 ", NO_FLAGS))); |
| 145 | 146 |
| 146 CHECK_EQ(0.0, StringToDouble(&uc, "0e0", ALLOW_HEX | ALLOW_OCTALS)); | 147 CHECK_EQ(0.0, StringToDouble(&uc, "0e0", ALLOW_HEX | ALLOW_OCTALS)); |
| 147 CHECK_EQ(0.0, StringToDouble(&uc, "0e1", ALLOW_HEX | ALLOW_OCTALS)); | 148 CHECK_EQ(0.0, StringToDouble(&uc, "0e1", ALLOW_HEX | ALLOW_OCTALS)); |
| 148 CHECK_EQ(0.0, StringToDouble(&uc, "0e-1", ALLOW_HEX | ALLOW_OCTALS)); | 149 CHECK_EQ(0.0, StringToDouble(&uc, "0e-1", ALLOW_HEX | ALLOW_OCTALS)); |
| 149 CHECK_EQ(0.0, StringToDouble(&uc, "0e-100000", ALLOW_HEX | ALLOW_OCTALS)); | 150 CHECK_EQ(0.0, StringToDouble(&uc, "0e-100000", ALLOW_HEX | ALLOW_OCTALS)); |
| 150 CHECK_EQ(0.0, StringToDouble(&uc, "0e+100000", ALLOW_HEX | ALLOW_OCTALS)); | 151 CHECK_EQ(0.0, StringToDouble(&uc, "0e+100000", ALLOW_HEX | ALLOW_OCTALS)); |
| 151 CHECK_EQ(0.0, StringToDouble(&uc, "0.", ALLOW_HEX | ALLOW_OCTALS)); | 152 CHECK_EQ(0.0, StringToDouble(&uc, "0.", ALLOW_HEX | ALLOW_OCTALS)); |
| 152 } | 153 } |
| 153 | 154 |
| 155 |
| 154 TEST(LongNumberStr) { | 156 TEST(LongNumberStr) { |
| 155 UnicodeCache uc; | 157 UnicodeCache uc; |
| 156 CHECK_EQ(1e10, StringToDouble(&uc, "1" "0000000000", NO_FLAGS)); | 158 CHECK_EQ(1e10, StringToDouble(&uc, "1" "0000000000", NO_FLAGS)); |
| 157 CHECK_EQ(1e20, StringToDouble(&uc, "1" "0000000000" "0000000000", NO_FLAGS)); | 159 CHECK_EQ(1e20, StringToDouble(&uc, "1" "0000000000" "0000000000", NO_FLAGS)); |
| 158 | 160 |
| 159 CHECK_EQ(1e60, StringToDouble(&uc, "1" "0000000000" "0000000000" "0000000000" | 161 CHECK_EQ(1e60, StringToDouble(&uc, "1" "0000000000" "0000000000" "0000000000" |
| 160 "0000000000" "0000000000" "0000000000", NO_FLAGS)); | 162 "0000000000" "0000000000" "0000000000", NO_FLAGS)); |
| 161 | 163 |
| 162 CHECK_EQ(1e-2, StringToDouble(&uc, "." "0" "1", NO_FLAGS)); | 164 CHECK_EQ(1e-2, StringToDouble(&uc, "." "0" "1", NO_FLAGS)); |
| 163 CHECK_EQ(1e-11, StringToDouble(&uc, "." "0000000000" "1", NO_FLAGS)); | 165 CHECK_EQ(1e-11, StringToDouble(&uc, "." "0000000000" "1", NO_FLAGS)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 "6998291015625000000000000000000000000000000000e-308"; | 199 "6998291015625000000000000000000000000000000000e-308"; |
| 198 | 200 |
| 199 CHECK_EQ(4.4501477170144017780491e-308, StringToDouble(&uc, num, NO_FLAGS)); | 201 CHECK_EQ(4.4501477170144017780491e-308, StringToDouble(&uc, num, NO_FLAGS)); |
| 200 | 202 |
| 201 // Changes the result of strtod (at least in glibc implementation). | 203 // Changes the result of strtod (at least in glibc implementation). |
| 202 num[sizeof(num) - 8] = '1'; | 204 num[sizeof(num) - 8] = '1'; |
| 203 | 205 |
| 204 CHECK_EQ(4.4501477170144022721148e-308, StringToDouble(&uc, num, NO_FLAGS)); | 206 CHECK_EQ(4.4501477170144022721148e-308, StringToDouble(&uc, num, NO_FLAGS)); |
| 205 } | 207 } |
| 206 | 208 |
| 209 |
| 207 TEST(MinimumExponent) { | 210 TEST(MinimumExponent) { |
| 208 UnicodeCache uc; | 211 UnicodeCache uc; |
| 209 // Same test but with different point-position. | 212 // Same test but with different point-position. |
| 210 char num[] = | 213 char num[] = |
| 211 "445014771701440202508199667279499186358524265859260511351695091" | 214 "445014771701440202508199667279499186358524265859260511351695091" |
| 212 "228726223124931264069530541271189424317838013700808305231545782" | 215 "228726223124931264069530541271189424317838013700808305231545782" |
| 213 "515453032382772695923684574304409936197089118747150815050941806" | 216 "515453032382772695923684574304409936197089118747150815050941806" |
| 214 "048037511737832041185193533879641611520514874130831632725201246" | 217 "048037511737832041185193533879641611520514874130831632725201246" |
| 215 "060231058690536206311752656217652146466431814205051640436322226" | 218 "060231058690536206311752656217652146466431814205051640436322226" |
| 216 "680064743260560117135282915796422274554896821334728738317548403" | 219 "680064743260560117135282915796422274554896821334728738317548403" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // Test most significant bits. | 301 // Test most significant bits. |
| 299 x = V8_2PART_UINT64_C(0xE0000000, 00000000); | 302 x = V8_2PART_UINT64_C(0xE0000000, 00000000); |
| 300 CHECK(x == UpperBits::encode(7)); | 303 CHECK(x == UpperBits::encode(7)); |
| 301 CHECK_EQ(7, UpperBits::decode(x)); | 304 CHECK_EQ(7, UpperBits::decode(x)); |
| 302 | 305 |
| 303 // Test the 32/64-bit boundary bits. | 306 // Test the 32/64-bit boundary bits. |
| 304 x = V8_2PART_UINT64_C(0x00000001, 80000000); | 307 x = V8_2PART_UINT64_C(0x00000001, 80000000); |
| 305 CHECK(x == MiddleBits::encode(3)); | 308 CHECK(x == MiddleBits::encode(3)); |
| 306 CHECK_EQ(3, MiddleBits::decode(x)); | 309 CHECK_EQ(3, MiddleBits::decode(x)); |
| 307 } | 310 } |
| OLD | NEW |