v8  3.11.10(node0.8.26)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-strtod.cc
Go to the documentation of this file.
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 
3 #include <stdlib.h>
4 
5 #include "v8.h"
6 
7 #include "bignum.h"
8 #include "cctest.h"
9 #include "diy-fp.h"
10 #include "double.h"
11 #include "strtod.h"
12 
13 using namespace v8::internal;
14 
15 static Vector<const char> StringToVector(const char* str) {
16  return Vector<const char>(str, StrLength(str));
17 }
18 
19 
20 static double StrtodChar(const char* str, int exponent) {
21  return Strtod(StringToVector(str), exponent);
22 }
23 
24 
26  Vector<const char> vector;
27 
28  vector = StringToVector("0");
29  CHECK_EQ(0.0, Strtod(vector, 1));
30  CHECK_EQ(0.0, Strtod(vector, 2));
31  CHECK_EQ(0.0, Strtod(vector, -2));
32  CHECK_EQ(0.0, Strtod(vector, -999));
33  CHECK_EQ(0.0, Strtod(vector, +999));
34 
35  vector = StringToVector("1");
36  CHECK_EQ(1.0, Strtod(vector, 0));
37  CHECK_EQ(10.0, Strtod(vector, 1));
38  CHECK_EQ(100.0, Strtod(vector, 2));
39  CHECK_EQ(1e20, Strtod(vector, 20));
40  CHECK_EQ(1e22, Strtod(vector, 22));
41  CHECK_EQ(1e23, Strtod(vector, 23));
42  CHECK_EQ(1e35, Strtod(vector, 35));
43  CHECK_EQ(1e36, Strtod(vector, 36));
44  CHECK_EQ(1e37, Strtod(vector, 37));
45  CHECK_EQ(1e-1, Strtod(vector, -1));
46  CHECK_EQ(1e-2, Strtod(vector, -2));
47  CHECK_EQ(1e-5, Strtod(vector, -5));
48  CHECK_EQ(1e-20, Strtod(vector, -20));
49  CHECK_EQ(1e-22, Strtod(vector, -22));
50  CHECK_EQ(1e-23, Strtod(vector, -23));
51  CHECK_EQ(1e-25, Strtod(vector, -25));
52  CHECK_EQ(1e-39, Strtod(vector, -39));
53 
54  vector = StringToVector("2");
55  CHECK_EQ(2.0, Strtod(vector, 0));
56  CHECK_EQ(20.0, Strtod(vector, 1));
57  CHECK_EQ(200.0, Strtod(vector, 2));
58  CHECK_EQ(2e20, Strtod(vector, 20));
59  CHECK_EQ(2e22, Strtod(vector, 22));
60  CHECK_EQ(2e23, Strtod(vector, 23));
61  CHECK_EQ(2e35, Strtod(vector, 35));
62  CHECK_EQ(2e36, Strtod(vector, 36));
63  CHECK_EQ(2e37, Strtod(vector, 37));
64  CHECK_EQ(2e-1, Strtod(vector, -1));
65  CHECK_EQ(2e-2, Strtod(vector, -2));
66  CHECK_EQ(2e-5, Strtod(vector, -5));
67  CHECK_EQ(2e-20, Strtod(vector, -20));
68  CHECK_EQ(2e-22, Strtod(vector, -22));
69  CHECK_EQ(2e-23, Strtod(vector, -23));
70  CHECK_EQ(2e-25, Strtod(vector, -25));
71  CHECK_EQ(2e-39, Strtod(vector, -39));
72 
73  vector = StringToVector("9");
74  CHECK_EQ(9.0, Strtod(vector, 0));
75  CHECK_EQ(90.0, Strtod(vector, 1));
76  CHECK_EQ(900.0, Strtod(vector, 2));
77  CHECK_EQ(9e20, Strtod(vector, 20));
78  CHECK_EQ(9e22, Strtod(vector, 22));
79  CHECK_EQ(9e23, Strtod(vector, 23));
80  CHECK_EQ(9e35, Strtod(vector, 35));
81  CHECK_EQ(9e36, Strtod(vector, 36));
82  CHECK_EQ(9e37, Strtod(vector, 37));
83  CHECK_EQ(9e-1, Strtod(vector, -1));
84  CHECK_EQ(9e-2, Strtod(vector, -2));
85  CHECK_EQ(9e-5, Strtod(vector, -5));
86  CHECK_EQ(9e-20, Strtod(vector, -20));
87  CHECK_EQ(9e-22, Strtod(vector, -22));
88  CHECK_EQ(9e-23, Strtod(vector, -23));
89  CHECK_EQ(9e-25, Strtod(vector, -25));
90  CHECK_EQ(9e-39, Strtod(vector, -39));
91 
92  vector = StringToVector("12345");
93  CHECK_EQ(12345.0, Strtod(vector, 0));
94  CHECK_EQ(123450.0, Strtod(vector, 1));
95  CHECK_EQ(1234500.0, Strtod(vector, 2));
96  CHECK_EQ(12345e20, Strtod(vector, 20));
97  CHECK_EQ(12345e22, Strtod(vector, 22));
98  CHECK_EQ(12345e23, Strtod(vector, 23));
99  CHECK_EQ(12345e30, Strtod(vector, 30));
100  CHECK_EQ(12345e31, Strtod(vector, 31));
101  CHECK_EQ(12345e32, Strtod(vector, 32));
102  CHECK_EQ(12345e35, Strtod(vector, 35));
103  CHECK_EQ(12345e36, Strtod(vector, 36));
104  CHECK_EQ(12345e37, Strtod(vector, 37));
105  CHECK_EQ(12345e-1, Strtod(vector, -1));
106  CHECK_EQ(12345e-2, Strtod(vector, -2));
107  CHECK_EQ(12345e-5, Strtod(vector, -5));
108  CHECK_EQ(12345e-20, Strtod(vector, -20));
109  CHECK_EQ(12345e-22, Strtod(vector, -22));
110  CHECK_EQ(12345e-23, Strtod(vector, -23));
111  CHECK_EQ(12345e-25, Strtod(vector, -25));
112  CHECK_EQ(12345e-39, Strtod(vector, -39));
113 
114  vector = StringToVector("12345678901234");
115  CHECK_EQ(12345678901234.0, Strtod(vector, 0));
116  CHECK_EQ(123456789012340.0, Strtod(vector, 1));
117  CHECK_EQ(1234567890123400.0, Strtod(vector, 2));
118  CHECK_EQ(12345678901234e20, Strtod(vector, 20));
119  CHECK_EQ(12345678901234e22, Strtod(vector, 22));
120  CHECK_EQ(12345678901234e23, Strtod(vector, 23));
121  CHECK_EQ(12345678901234e30, Strtod(vector, 30));
122  CHECK_EQ(12345678901234e31, Strtod(vector, 31));
123  CHECK_EQ(12345678901234e32, Strtod(vector, 32));
124  CHECK_EQ(12345678901234e35, Strtod(vector, 35));
125  CHECK_EQ(12345678901234e36, Strtod(vector, 36));
126  CHECK_EQ(12345678901234e37, Strtod(vector, 37));
127  CHECK_EQ(12345678901234e-1, Strtod(vector, -1));
128  CHECK_EQ(12345678901234e-2, Strtod(vector, -2));
129  CHECK_EQ(12345678901234e-5, Strtod(vector, -5));
130  CHECK_EQ(12345678901234e-20, Strtod(vector, -20));
131  CHECK_EQ(12345678901234e-22, Strtod(vector, -22));
132  CHECK_EQ(12345678901234e-23, Strtod(vector, -23));
133  CHECK_EQ(12345678901234e-25, Strtod(vector, -25));
134  CHECK_EQ(12345678901234e-39, Strtod(vector, -39));
135 
136  vector = StringToVector("123456789012345");
137  CHECK_EQ(123456789012345.0, Strtod(vector, 0));
138  CHECK_EQ(1234567890123450.0, Strtod(vector, 1));
139  CHECK_EQ(12345678901234500.0, Strtod(vector, 2));
140  CHECK_EQ(123456789012345e20, Strtod(vector, 20));
141  CHECK_EQ(123456789012345e22, Strtod(vector, 22));
142  CHECK_EQ(123456789012345e23, Strtod(vector, 23));
143  CHECK_EQ(123456789012345e35, Strtod(vector, 35));
144  CHECK_EQ(123456789012345e36, Strtod(vector, 36));
145  CHECK_EQ(123456789012345e37, Strtod(vector, 37));
146  CHECK_EQ(123456789012345e39, Strtod(vector, 39));
147  CHECK_EQ(123456789012345e-1, Strtod(vector, -1));
148  CHECK_EQ(123456789012345e-2, Strtod(vector, -2));
149  CHECK_EQ(123456789012345e-5, Strtod(vector, -5));
150  CHECK_EQ(123456789012345e-20, Strtod(vector, -20));
151  CHECK_EQ(123456789012345e-22, Strtod(vector, -22));
152  CHECK_EQ(123456789012345e-23, Strtod(vector, -23));
153  CHECK_EQ(123456789012345e-25, Strtod(vector, -25));
154  CHECK_EQ(123456789012345e-39, Strtod(vector, -39));
155 
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));
161  // It would be more readable to put non-zero literals on the left side (i.e.
162  // CHECK_EQ(1e-325, StrtodChar("1", -325))), but then Gcc complains that
163  // they are truncated to zero.
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));
176 
177  // It would be more readable to put the literals (and not V8_INFINITY) on the
178  // left side (i.e. CHECK_EQ(1e309, StrtodChar("1", 309))), but then Gcc
179  // complains that the floating constant exceeds range of 'double'.
180  CHECK_EQ(V8_INFINITY, StrtodChar("1", 309));
181  CHECK_EQ(1e308, StrtodChar("1", 308));
182  CHECK_EQ(1234e305, StrtodChar("1234", 305));
183  CHECK_EQ(1234e304, StrtodChar("1234", 304));
184  CHECK_EQ(V8_INFINITY, StrtodChar("18", 307));
185  CHECK_EQ(17e307, StrtodChar("17", 307));
186  CHECK_EQ(V8_INFINITY, StrtodChar("0000001", 309));
187  CHECK_EQ(1e308, StrtodChar("00000001", 308));
188  CHECK_EQ(1234e305, StrtodChar("00000001234", 305));
189  CHECK_EQ(1234e304, StrtodChar("000000001234", 304));
190  CHECK_EQ(V8_INFINITY, StrtodChar("0000000018", 307));
191  CHECK_EQ(17e307, StrtodChar("0000000017", 307));
192  CHECK_EQ(V8_INFINITY, StrtodChar("1000000", 303));
193  CHECK_EQ(1e308, StrtodChar("100000", 303));
194  CHECK_EQ(1234e305, StrtodChar("123400000", 300));
195  CHECK_EQ(1234e304, StrtodChar("123400000", 299));
196  CHECK_EQ(V8_INFINITY, StrtodChar("180000000", 300));
197  CHECK_EQ(17e307, StrtodChar("170000000", 300));
198  CHECK_EQ(V8_INFINITY, StrtodChar("00000001000000", 303));
199  CHECK_EQ(1e308, StrtodChar("000000000000100000", 303));
200  CHECK_EQ(1234e305, StrtodChar("00000000123400000", 300));
201  CHECK_EQ(1234e304, StrtodChar("0000000123400000", 299));
202  CHECK_EQ(V8_INFINITY, StrtodChar("00000000180000000", 300));
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));
206  CHECK_EQ(V8_INFINITY, StrtodChar("17976931348623159", 292));
207 
208  // The following number is the result of 89255.0/1e22. Both floating-point
209  // numbers can be accurately represented with doubles. However on Linux,x86
210  // the floating-point stack is set to 80bits and the double-rounding
211  // introduces an error.
212  CHECK_EQ(89255e-22, StrtodChar("89255", -22));
213 
214  // Some random values.
215  CHECK_EQ(358416272e-33, StrtodChar("358416272", -33));
216  CHECK_EQ(104110013277974872254e-225,
217  StrtodChar("104110013277974872254", -225));
218 
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));
227 
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));
244 
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));
261 
262  CHECK_EQ(5.445618932859895e-255,
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));
278 
279  // Boundary cases. Boundaries themselves should round to even.
280  //
281  // 0x1FFFFFFFFFFFF * 2^3 = 72057594037927928
282  // next: 72057594037927936
283  // boundary: 72057594037927932 should round up.
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));
289 
290  // 0x1FFFFFFFFFFFF * 2^10 = 9223372036854774784
291  // next: 9223372036854775808
292  // boundary: 9223372036854775296 should round up.
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));
298 
299  // 0x1FFFFFFFFFFFF * 2^50 = 10141204801825834086073718800384
300  // next: 10141204801825835211973625643008
301  // boundary: 10141204801825834649023672221696 should round up.
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));
312 
313  // 0x1FFFFFFFFFFFF * 2^99 = 5708990770823838890407843763683279797179383808
314  // next: 5708990770823839524233143877797980545530986496
315  // boundary: 5708990770823839207320493820740630171355185152
316  // The boundary should round up.
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));
327 
328  // The following test-cases got some public attention in early 2011 when they
329  // sent Java and PHP into an infinite loop.
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));
346 }
347 
348 
349 static int CompareBignumToDiyFp(const Bignum& bignum_digits,
350  int bignum_exponent,
351  DiyFp diy_fp) {
352  Bignum bignum;
353  bignum.AssignBignum(bignum_digits);
354  Bignum other;
355  other.AssignUInt64(diy_fp.f());
356  if (bignum_exponent >= 0) {
357  bignum.MultiplyByPowerOfTen(bignum_exponent);
358  } else {
359  other.MultiplyByPowerOfTen(-bignum_exponent);
360  }
361  if (diy_fp.e() >= 0) {
362  other.ShiftLeft(diy_fp.e());
363  } else {
364  bignum.ShiftLeft(-diy_fp.e());
365  }
366  return Bignum::Compare(bignum, other);
367 }
368 
369 
370 static bool CheckDouble(Vector<const char> buffer,
371  int exponent,
372  double to_check) {
373  DiyFp lower_boundary;
374  DiyFp upper_boundary;
375  Bignum input_digits;
376  input_digits.AssignDecimalString(buffer);
377  if (to_check == 0.0) {
378  const double kMinDouble = 4e-324;
379  // Check that the buffer*10^exponent < (0 + kMinDouble)/2.
380  Double d(kMinDouble);
381  d.NormalizedBoundaries(&lower_boundary, &upper_boundary);
382  return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) <= 0;
383  }
384  if (to_check == V8_INFINITY) {
385  const double kMaxDouble = 1.7976931348623157e308;
386  // Check that the buffer*10^exponent >= boundary between kMaxDouble and inf.
387  Double d(kMaxDouble);
388  d.NormalizedBoundaries(&lower_boundary, &upper_boundary);
389  return CompareBignumToDiyFp(input_digits, exponent, upper_boundary) >= 0;
390  }
391  Double d(to_check);
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;
396  } else {
397  return CompareBignumToDiyFp(input_digits, exponent, lower_boundary) > 0 &&
398  CompareBignumToDiyFp(input_digits, exponent, upper_boundary) < 0;
399  }
400 }
401 
402 
403 // Copied from v8.cc and adapted to make the function deterministic.
404 static uint32_t DeterministicRandom() {
405  // Random number generator using George Marsaglia's MWC algorithm.
406  static uint32_t hi = 0;
407  static uint32_t lo = 0;
408 
409  // Initialization values don't have any special meaning. (They are the result
410  // of two calls to random().)
411  if (hi == 0) hi = 0xbfe166e7;
412  if (lo == 0) lo = 0x64d1c3c9;
413 
414  // Mix the bits.
415  hi = 36969 * (hi & 0xFFFF) + (hi >> 16);
416  lo = 18273 * (lo & 0xFFFF) + (lo >> 16);
417  return (hi << 16) + (lo & 0xFFFF);
418 }
419 
420 
421 static const int kBufferSize = 1024;
422 static const int kShortStrtodRandomCount = 2;
423 static const int kLargeStrtodRandomCount = 2;
424 
425 TEST(RandomStrtod) {
426  char buffer[kBufferSize];
427  for (int length = 1; length < 15; length++) {
428  for (int i = 0; i < kShortStrtodRandomCount; ++i) {
429  int pos = 0;
430  for (int j = 0; j < length; ++j) {
431  buffer[pos++] = random() % 10 + '0';
432  }
433  int exponent = DeterministicRandom() % (25*2 + 1) - 25 - length;
434  buffer[pos] = '\0';
435  Vector<const char> vector(buffer, pos);
436  double strtod_result = Strtod(vector, exponent);
437  CHECK(CheckDouble(vector, exponent, strtod_result));
438  }
439  }
440  for (int length = 15; length < 800; length += 2) {
441  for (int i = 0; i < kLargeStrtodRandomCount; ++i) {
442  int pos = 0;
443  for (int j = 0; j < length; ++j) {
444  buffer[pos++] = random() % 10 + '0';
445  }
446  int exponent = DeterministicRandom() % (308*2 + 1) - 308 - length;
447  buffer[pos] = '\0';
448  Vector<const char> vector(buffer, pos);
449  double strtod_result = Strtod(vector, exponent);
450  CHECK(CheckDouble(vector, exponent, strtod_result));
451  }
452  }
453 }
void AssignBignum(const Bignum &other)
Definition: bignum.cc:77
int random()
#define CHECK_EQ(expected, value)
Definition: checks.h:219
uint64_t f() const
Definition: diy-fp.h:102
void AssignUInt64(uint64_t value)
Definition: bignum.cc:60
#define CHECK(condition)
Definition: checks.h:56
static int Compare(const Bignum &a, const Bignum &b)
Definition: bignum.cc:617
#define V8_INFINITY
Definition: globals.h:32
double Strtod(Vector< const char > buffer, int exponent)
Definition: strtod.cc:417
int e() const
Definition: diy-fp.h:103
void ShiftLeft(int shift_amount)
Definition: bignum.cc:240
int StrLength(const char *string)
Definition: utils.h:234
void AssignDecimalString(Vector< const char > value)
Definition: bignum.cc:103
void MultiplyByPowerOfTen(int exponent)
Definition: bignum.cc:302