13 using namespace v8::internal;
20 static double StrtodChar(
const char* str,
int exponent) {
21 return Strtod(StringToVector(str), exponent);
28 vector = StringToVector(
"0");
35 vector = StringToVector(
"1");
54 vector = StringToVector(
"2");
73 vector = StringToVector(
"9");
92 vector = StringToVector(
"12345");
114 vector = StringToVector(
"12345678901234");
136 vector = StringToVector(
"123456789012345");
156 CHECK_EQ(0.0, StrtodChar(
"0", 12345));
157 CHECK_EQ(0.0, StrtodChar(
"", 1324));
158 CHECK_EQ(0.0, StrtodChar(
"000000000", 123));
159 CHECK_EQ(0.0, StrtodChar(
"2", -324));
160 CHECK_EQ(4e-324, StrtodChar(
"3", -324));
164 CHECK_EQ(0.0, StrtodChar(
"1", -325));
165 CHECK_EQ(0.0, StrtodChar(
"1", -325));
166 CHECK_EQ(0.0, StrtodChar(
"20000", -328));
167 CHECK_EQ(40000e-328, StrtodChar(
"30000", -328));
168 CHECK_EQ(0.0, StrtodChar(
"10000", -329));
169 CHECK_EQ(0.0, StrtodChar(
"90000", -329));
170 CHECK_EQ(0.0, StrtodChar(
"000000001", -325));
171 CHECK_EQ(0.0, StrtodChar(
"000000001", -325));
172 CHECK_EQ(0.0, StrtodChar(
"0000000020000", -328));
173 CHECK_EQ(40000e-328, StrtodChar(
"00000030000", -328));
174 CHECK_EQ(0.0, StrtodChar(
"0000000010000", -329));
175 CHECK_EQ(0.0, StrtodChar(
"0000000090000", -329));
181 CHECK_EQ(1e308, StrtodChar(
"1", 308));
182 CHECK_EQ(1234e305, StrtodChar(
"1234", 305));
183 CHECK_EQ(1234e304, StrtodChar(
"1234", 304));
185 CHECK_EQ(17e307, StrtodChar(
"17", 307));
187 CHECK_EQ(1e308, StrtodChar(
"00000001", 308));
188 CHECK_EQ(1234e305, StrtodChar(
"00000001234", 305));
189 CHECK_EQ(1234e304, StrtodChar(
"000000001234", 304));
191 CHECK_EQ(17e307, StrtodChar(
"0000000017", 307));
193 CHECK_EQ(1e308, StrtodChar(
"100000", 303));
194 CHECK_EQ(1234e305, StrtodChar(
"123400000", 300));
195 CHECK_EQ(1234e304, StrtodChar(
"123400000", 299));
197 CHECK_EQ(17e307, StrtodChar(
"170000000", 300));
199 CHECK_EQ(1e308, StrtodChar(
"000000000000100000", 303));
200 CHECK_EQ(1234e305, StrtodChar(
"00000000123400000", 300));
201 CHECK_EQ(1234e304, StrtodChar(
"0000000123400000", 299));
203 CHECK_EQ(17e307, StrtodChar(
"00000000170000000", 300));
204 CHECK_EQ(1.7976931348623157E+308, StrtodChar(
"17976931348623157", 292));
205 CHECK_EQ(1.7976931348623158E+308, StrtodChar(
"17976931348623158", 292));
212 CHECK_EQ(89255e-22, StrtodChar(
"89255", -22));
215 CHECK_EQ(358416272e-33, StrtodChar(
"358416272", -33));
216 CHECK_EQ(104110013277974872254e-225,
217 StrtodChar(
"104110013277974872254", -225));
219 CHECK_EQ(123456789e108, StrtodChar(
"123456789", 108));
220 CHECK_EQ(123456789e109, StrtodChar(
"123456789", 109));
221 CHECK_EQ(123456789e110, StrtodChar(
"123456789", 110));
222 CHECK_EQ(123456789e111, StrtodChar(
"123456789", 111));
223 CHECK_EQ(123456789e112, StrtodChar(
"123456789", 112));
224 CHECK_EQ(123456789e113, StrtodChar(
"123456789", 113));
225 CHECK_EQ(123456789e114, StrtodChar(
"123456789", 114));
226 CHECK_EQ(123456789e115, StrtodChar(
"123456789", 115));
228 CHECK_EQ(1234567890123456789012345e108,
229 StrtodChar(
"1234567890123456789012345", 108));
230 CHECK_EQ(1234567890123456789012345e109,
231 StrtodChar(
"1234567890123456789012345", 109));
232 CHECK_EQ(1234567890123456789012345e110,
233 StrtodChar(
"1234567890123456789012345", 110));
234 CHECK_EQ(1234567890123456789012345e111,
235 StrtodChar(
"1234567890123456789012345", 111));
236 CHECK_EQ(1234567890123456789012345e112,
237 StrtodChar(
"1234567890123456789012345", 112));
238 CHECK_EQ(1234567890123456789012345e113,
239 StrtodChar(
"1234567890123456789012345", 113));
240 CHECK_EQ(1234567890123456789012345e114,
241 StrtodChar(
"1234567890123456789012345", 114));
242 CHECK_EQ(1234567890123456789012345e115,
243 StrtodChar(
"1234567890123456789012345", 115));
245 CHECK_EQ(1234567890123456789052345e108,
246 StrtodChar(
"1234567890123456789052345", 108));
247 CHECK_EQ(1234567890123456789052345e109,
248 StrtodChar(
"1234567890123456789052345", 109));
249 CHECK_EQ(1234567890123456789052345e110,
250 StrtodChar(
"1234567890123456789052345", 110));
251 CHECK_EQ(1234567890123456789052345e111,
252 StrtodChar(
"1234567890123456789052345", 111));
253 CHECK_EQ(1234567890123456789052345e112,
254 StrtodChar(
"1234567890123456789052345", 112));
255 CHECK_EQ(1234567890123456789052345e113,
256 StrtodChar(
"1234567890123456789052345", 113));
257 CHECK_EQ(1234567890123456789052345e114,
258 StrtodChar(
"1234567890123456789052345", 114));
259 CHECK_EQ(1234567890123456789052345e115,
260 StrtodChar(
"1234567890123456789052345", 115));
263 StrtodChar(
"5445618932859895362967233318697132813618813095743952975"
264 "4392982234069699615600475529427176366709107287468930197"
265 "8628345413991790019316974825934906752493984055268219809"
266 "5012176093045431437495773903922425632551857520884625114"
267 "6241265881735209066709685420744388526014389929047617597"
268 "0302268848374508109029268898695825171158085457567481507"
269 "4162979705098246243690189880319928315307816832576838178"
270 "2563074014542859888710209237525873301724479666744537857"
271 "9026553346649664045621387124193095870305991178772256504"
272 "4368663670643970181259143319016472430928902201239474588"
273 "1392338901353291306607057623202353588698746085415097902"
274 "6640064319118728664842287477491068264828851624402189317"
275 "2769161449825765517353755844373640588822904791244190695"
276 "2998382932630754670573838138825217065450843010498555058"
277 "88186560731", -1035));
284 CHECK_EQ(72057594037927928.0, StrtodChar(
"72057594037927928", 0));
285 CHECK_EQ(72057594037927936.0, StrtodChar(
"72057594037927936", 0));
286 CHECK_EQ(72057594037927936.0, StrtodChar(
"72057594037927932", 0));
287 CHECK_EQ(72057594037927928.0, StrtodChar(
"7205759403792793199999", -5));
288 CHECK_EQ(72057594037927936.0, StrtodChar(
"7205759403792793200001", -5));
293 CHECK_EQ(9223372036854774784.0, StrtodChar(
"9223372036854774784", 0));
294 CHECK_EQ(9223372036854775808.0, StrtodChar(
"9223372036854775808", 0));
295 CHECK_EQ(9223372036854775808.0, StrtodChar(
"9223372036854775296", 0));
296 CHECK_EQ(9223372036854774784.0, StrtodChar(
"922337203685477529599999", -5));
297 CHECK_EQ(9223372036854775808.0, StrtodChar(
"922337203685477529600001", -5));
302 CHECK_EQ(10141204801825834086073718800384.0,
303 StrtodChar(
"10141204801825834086073718800384", 0));
304 CHECK_EQ(10141204801825835211973625643008.0,
305 StrtodChar(
"10141204801825835211973625643008", 0));
306 CHECK_EQ(10141204801825835211973625643008.0,
307 StrtodChar(
"10141204801825834649023672221696", 0));
308 CHECK_EQ(10141204801825834086073718800384.0,
309 StrtodChar(
"1014120480182583464902367222169599999", -5));
310 CHECK_EQ(10141204801825835211973625643008.0,
311 StrtodChar(
"1014120480182583464902367222169600001", -5));
317 CHECK_EQ(5708990770823838890407843763683279797179383808.0,
318 StrtodChar(
"5708990770823838890407843763683279797179383808", 0));
319 CHECK_EQ(5708990770823839524233143877797980545530986496.0,
320 StrtodChar(
"5708990770823839524233143877797980545530986496", 0));
321 CHECK_EQ(5708990770823839524233143877797980545530986496.0,
322 StrtodChar(
"5708990770823839207320493820740630171355185152", 0));
323 CHECK_EQ(5708990770823838890407843763683279797179383808.0,
324 StrtodChar(
"5708990770823839207320493820740630171355185151999", -3));
325 CHECK_EQ(5708990770823839524233143877797980545530986496.0,
326 StrtodChar(
"5708990770823839207320493820740630171355185152001", -3));
330 CHECK_EQ(2.225073858507201e-308, StrtodChar(
"22250738585072011", -324));
331 CHECK_EQ(2.22507385850720138309e-308,
332 StrtodChar(
"22250738585072011360574097967091319759348195463516456480"
333 "23426109724822222021076945516529523908135087914149158913"
334 "03962110687008643869459464552765720740782062174337998814"
335 "10632673292535522868813721490129811224514518898490572223"
336 "07285255133155755015914397476397983411801999323962548289"
337 "01710708185069063066665599493827577257201576306269066333"
338 "26475653000092458883164330377797918696120494973903778297"
339 "04905051080609940730262937128958950003583799967207254304"
340 "36028407889577179615094551674824347103070260914462157228"
341 "98802581825451803257070188608721131280795122334262883686"
342 "22321503775666622503982534335974568884423900265498198385"
343 "48794829220689472168983109969836584681402285424333066033"
344 "98508864458040010349339704275671864433837704860378616227"
345 "71738545623065874679014086723327636718751", -1076));
349 static int CompareBignumToDiyFp(
const Bignum& bignum_digits,
356 if (bignum_exponent >= 0) {
361 if (diy_fp.
e() >= 0) {
373 DiyFp lower_boundary;
374 DiyFp upper_boundary;
377 if (to_check == 0.0) {
378 const double kMinDouble = 4e-324;
381 d.NormalizedBoundaries(&lower_boundary, &upper_boundary);
382 return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) <= 0;
385 const double kMaxDouble = 1.7976931348623157e308;
388 d.NormalizedBoundaries(&lower_boundary, &upper_boundary);
389 return CompareBignumToDiyFp(input_digits, exponent, upper_boundary) >= 0;
392 d.NormalizedBoundaries(&lower_boundary, &upper_boundary);
393 if ((d.Significand() & 1) == 0) {
394 return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) >= 0 &&
395 CompareBignumToDiyFp(input_digits, exponent, upper_boundary) <= 0;
397 return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) > 0 &&
398 CompareBignumToDiyFp(input_digits, exponent, upper_boundary) < 0;
404 static uint32_t DeterministicRandom() {
406 static uint32_t
hi = 0;
407 static uint32_t
lo = 0;
411 if (hi == 0) hi = 0xbfe166e7;
412 if (lo == 0) lo = 0x64d1c3c9;
415 hi = 36969 * (hi & 0xFFFF) + (hi >> 16);
416 lo = 18273 * (lo & 0xFFFF) + (lo >> 16);
417 return (hi << 16) + (lo & 0xFFFF);
421 static const int kBufferSize = 1024;
422 static const int kShortStrtodRandomCount = 2;
423 static const int kLargeStrtodRandomCount = 2;
426 char buffer[kBufferSize];
427 for (
int length = 1; length < 15; length++) {
428 for (
int i = 0; i < kShortStrtodRandomCount; ++i) {
430 for (
int j = 0; j < length; ++j) {
431 buffer[pos++] =
random() % 10 +
'0';
433 int exponent = DeterministicRandom() % (25*2 + 1) - 25 - length;
436 double strtod_result =
Strtod(vector, exponent);
437 CHECK(CheckDouble(vector, exponent, strtod_result));
440 for (
int length = 15; length < 800; length += 2) {
441 for (
int i = 0; i < kLargeStrtodRandomCount; ++i) {
443 for (
int j = 0; j < length; ++j) {
444 buffer[pos++] =
random() % 10 +
'0';
446 int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length;
449 double strtod_result =
Strtod(vector, exponent);
450 CHECK(CheckDouble(vector, exponent, strtod_result));
void AssignBignum(const Bignum &other)
#define CHECK_EQ(expected, value)
void AssignUInt64(uint64_t value)
static int Compare(const Bignum &a, const Bignum &b)
double Strtod(Vector< const char > buffer, int exponent)
void ShiftLeft(int shift_amount)
int StrLength(const char *string)
void AssignDecimalString(Vector< const char > value)
void MultiplyByPowerOfTen(int exponent)