OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 // then false is returned. This usually happens rarely (~0.5%). | 307 // then false is returned. This usually happens rarely (~0.5%). |
308 // | 308 // |
309 // Say, for the sake of example, that | 309 // Say, for the sake of example, that |
310 // w.e() == -48, and w.f() == 0x1234567890abcdef | 310 // w.e() == -48, and w.f() == 0x1234567890abcdef |
311 // w's value can be computed by w.f() * 2^w.e() | 311 // w's value can be computed by w.f() * 2^w.e() |
312 // We can obtain w's integral digits by simply shifting w.f() by -w.e(). | 312 // We can obtain w's integral digits by simply shifting w.f() by -w.e(). |
313 // -> w's integral part is 0x1234 | 313 // -> w's integral part is 0x1234 |
314 // w's fractional part is therefore 0x567890abcdef. | 314 // w's fractional part is therefore 0x567890abcdef. |
315 // Printing w's integral part is easy (simply print 0x1234 in decimal). | 315 // Printing w's integral part is easy (simply print 0x1234 in decimal). |
316 // In order to print its fraction we repeatedly multiply the fraction by 10 and | 316 // In order to print its fraction we repeatedly multiply the fraction by 10 and |
317 // get each digit. Example the first digit after the point would be computed by | 317 // get each digit. Example the first digit after the comma would be computed by |
318 // (0x567890abcdef * 10) >> 48. -> 3 | 318 // (0x567890abcdef * 10) >> 48. -> 3 |
319 // The whole thing becomes slightly more complicated because we want to stop | 319 // The whole thing becomes slightly more complicated because we want to stop |
320 // once we have enough digits. That is, once the digits inside the buffer | 320 // once we have enough digits. That is, once the digits inside the buffer |
321 // represent 'w' we can stop. Everything inside the interval low - high | 321 // represent 'w' we can stop. Everything inside the interval low - high |
322 // represents w. However we have to pay attention to low, high and w's | 322 // represents w. However we have to pay attention to low, high and w's |
323 // imprecision. | 323 // imprecision. |
324 bool DigitGen(DiyFp low, | 324 bool DigitGen(DiyFp low, |
325 DiyFp w, | 325 DiyFp w, |
326 DiyFp high, | 326 DiyFp high, |
327 Vector<char> buffer, | 327 Vector<char> buffer, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 int kappa; | 483 int kappa; |
484 bool result = DigitGen(scaled_boundary_minus, scaled_w, scaled_boundary_plus, | 484 bool result = DigitGen(scaled_boundary_minus, scaled_w, scaled_boundary_plus, |
485 buffer, length, &kappa); | 485 buffer, length, &kappa); |
486 *decimal_exponent = -mk + kappa; | 486 *decimal_exponent = -mk + kappa; |
487 return result; | 487 return result; |
488 } | 488 } |
489 | 489 |
490 | 490 |
491 bool FastDtoa(double v, | 491 bool FastDtoa(double v, |
492 Vector<char> buffer, | 492 Vector<char> buffer, |
| 493 int* sign, |
493 int* length, | 494 int* length, |
494 int* point) { | 495 int* point) { |
495 ASSERT(v > 0); | 496 ASSERT(v != 0); |
496 ASSERT(!Double(v).IsSpecial()); | 497 ASSERT(!Double(v).IsSpecial()); |
497 | 498 |
| 499 if (v < 0) { |
| 500 v = -v; |
| 501 *sign = 1; |
| 502 } else { |
| 503 *sign = 0; |
| 504 } |
498 int decimal_exponent; | 505 int decimal_exponent; |
499 bool result = grisu3(v, buffer, length, &decimal_exponent); | 506 bool result = grisu3(v, buffer, length, &decimal_exponent); |
500 *point = *length + decimal_exponent; | 507 *point = *length + decimal_exponent; |
501 buffer[*length] = '\0'; | 508 buffer[*length] = '\0'; |
502 return result; | 509 return result; |
503 } | 510 } |
504 | 511 |
505 } } // namespace v8::internal | 512 } } // namespace v8::internal |
OLD | NEW |