Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: third_party/WebKit/Source/platform/wtf/dtoa/fast-dtoa.cc

Issue 2839663003: Replace ASSERT with DHCECK_op in platform/wtf (Closed)
Patch Set: fix indentation Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // There are 3 conditions that stop the decrementation process: 133 // There are 3 conditions that stop the decrementation process:
134 // 1) the buffer is already below w_high 134 // 1) the buffer is already below w_high
135 // 2) decrementing the buffer would make it leave the unsafe interval 135 // 2) decrementing the buffer would make it leave the unsafe interval
136 // 3) decrementing the buffer would yield a number below w_high and fa rther 136 // 3) decrementing the buffer would yield a number below w_high and fa rther
137 // away than the current number. In other words: 137 // away than the current number. In other words:
138 // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high 138 // (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high
139 // Instead of using the buffer directly we use its distance to too_high. 139 // Instead of using the buffer directly we use its distance to too_high.
140 // Conceptually rest ~= too_high - buffer 140 // Conceptually rest ~= too_high - buffer
141 // We need to do the following tests in this order to avoid over- and 141 // We need to do the following tests in this order to avoid over- and
142 // underflows. 142 // underflows.
143 ASSERT(rest <= unsafe_interval); 143 DCHECK_LE(rest, unsafe_interval);
144 while (rest < small_distance && // Negated condition 1 144 while (rest < small_distance && // Negated condition 1
145 unsafe_interval - rest >= ten_kappa && // Negated condition 2 145 unsafe_interval - rest >= ten_kappa && // Negated condition 2
146 (rest + ten_kappa < small_distance || // buffer{-1} > w_high 146 (rest + ten_kappa < small_distance || // buffer{-1} > w_high
147 small_distance - rest >= rest + ten_kappa - small_distance)) { 147 small_distance - rest >= rest + ten_kappa - small_distance)) {
148 buffer[length - 1]--; 148 buffer[length - 1]--;
149 rest += ten_kappa; 149 rest += ten_kappa;
150 } 150 }
151 151
152 // We have approached w+ as much as possible. We now test if approaching w- 152 // We have approached w+ as much as possible. We now test if approaching w-
153 // would require changing the buffer. If yes, then we have two possible 153 // would require changing the buffer. If yes, then we have two possible
(...skipping 25 matching lines...) Expand all
179 // imprecision and returns false, if the rounding direction cannot be 179 // imprecision and returns false, if the rounding direction cannot be
180 // unambiguously determined. 180 // unambiguously determined.
181 // 181 //
182 // Precondition: rest < ten_kappa. 182 // Precondition: rest < ten_kappa.
183 static bool RoundWeedCounted(Vector<char> buffer, 183 static bool RoundWeedCounted(Vector<char> buffer,
184 int length, 184 int length,
185 uint64_t rest, 185 uint64_t rest,
186 uint64_t ten_kappa, 186 uint64_t ten_kappa,
187 uint64_t unit, 187 uint64_t unit,
188 int* kappa) { 188 int* kappa) {
189 ASSERT(rest < ten_kappa); 189 DCHECK_LT(rest, ten_kappa);
190 // The following tests are done in a specific order to avoid overflows. They 190 // The following tests are done in a specific order to avoid overflows. They
191 // will work correctly with any uint64 values of rest < ten_kappa and un it. 191 // will work correctly with any uint64 values of rest < ten_kappa and un it.
192 // 192 //
193 // If the unit is too big, then we don't know which way to round. For ex ample 193 // If the unit is too big, then we don't know which way to round. For ex ample
194 // a unit of 50 means that the real number lies within rest +/- 50. If 194 // a unit of 50 means that the real number lies within rest +/- 50. If
195 // 10^kappa == 40 then there is no way to tell which way to round. 195 // 10^kappa == 40 then there is no way to tell which way to round.
196 if (unit >= ten_kappa) return false; 196 if (unit >= ten_kappa) return false;
197 // Even if unit is just half the size of 10^kappa we are already complet ely 197 // Even if unit is just half the size of 10^kappa we are already complet ely
198 // lost. (And after the previous test we know that the expression will n ot 198 // lost. (And after the previous test we know that the expression will n ot
199 // over/underflow.) 199 // over/underflow.)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 234
235 // Returns the biggest power of ten that is less than or equal to the given 235 // Returns the biggest power of ten that is less than or equal to the given
236 // number. We furthermore receive the maximum number of bits 'number' has. 236 // number. We furthermore receive the maximum number of bits 'number' has.
237 // If number_bits == 0 then 0^-1 is returned 237 // If number_bits == 0 then 0^-1 is returned
238 // The number of bits must be <= 32. 238 // The number of bits must be <= 32.
239 // Precondition: number < (1 << (number_bits + 1)). 239 // Precondition: number < (1 << (number_bits + 1)).
240 static void BiggestPowerTen(uint32_t number, 240 static void BiggestPowerTen(uint32_t number,
241 int number_bits, 241 int number_bits,
242 uint32_t* power, 242 uint32_t* power,
243 int* exponent) { 243 int* exponent) {
244 ASSERT(number < (uint32_t)(1 << (number_bits + 1))); 244 DCHECK_LT(number, (uint32_t)(1 << (number_bits + 1)));
245 245
246 switch (number_bits) { 246 switch (number_bits) {
247 case 32: 247 case 32:
248 case 31: 248 case 31:
249 case 30: 249 case 30:
250 if (kTen9 <= number) { 250 if (kTen9 <= number) {
251 *power = kTen9; 251 *power = kTen9;
252 *exponent = 9; 252 *exponent = 9;
253 break; 253 break;
254 } // else fallthrough 254 } // else fallthrough
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // once we have enough digits. That is, once the digits inside the buffer 380 // once we have enough digits. That is, once the digits inside the buffer
381 // represent 'w' we can stop. Everything inside the interval low - high 381 // represent 'w' we can stop. Everything inside the interval low - high
382 // represents w. However we have to pay attention to low, high and w's 382 // represents w. However we have to pay attention to low, high and w's
383 // imprecision. 383 // imprecision.
384 static bool DigitGen(DiyFp low, 384 static bool DigitGen(DiyFp low,
385 DiyFp w, 385 DiyFp w,
386 DiyFp high, 386 DiyFp high,
387 Vector<char> buffer, 387 Vector<char> buffer,
388 int* length, 388 int* length,
389 int* kappa) { 389 int* kappa) {
390 ASSERT(low.E() == w.E() && w.E() == high.E()); 390 DCHECK_EQ(low.E(), w.E());
391 ASSERT(low.F() + 1 <= high.F() - 1); 391 DCHECK_EQ(w.E(), high.E());
392 ASSERT(kMinimalTargetExponent <= w.E() && 392 DCHECK_LE(low.F() + 1, high.F() - 1);
393 w.E() <= kMaximalTargetExponent); 393 DCHECK_LE(kMinimalTargetExponent, w.E());
394 DCHECK_LE(w.E(), kMaximalTargetExponent);
394 // low, w and high are imprecise, but by less than one ulp (unit in the 395 // low, w and high are imprecise, but by less than one ulp (unit in the
395 // last place). If we remove (resp. add) 1 ulp from low (resp. high) we 396 // last place). If we remove (resp. add) 1 ulp from low (resp. high) we
396 // are certain that the new numbers are outside of the interval we want 397 // are certain that the new numbers are outside of the interval we want
397 // the final representation to lie in. Inversely adding (resp. removing) 1 398 // the final representation to lie in. Inversely adding (resp. removing) 1
398 // ulp from low (resp. high) would yield numbers that are certain to lie 399 // ulp from low (resp. high) would yield numbers that are certain to lie
399 // in the interval. We will use this fact later on. We will now start by 400 // in the interval. We will use this fact later on. We will now start by
400 // generating the digits within the uncertain interval. Later we will weed 401 // generating the digits within the uncertain interval. Later we will weed
401 // out representations that lie outside the safe interval and thus _might_ 402 // out representations that lie outside the safe interval and thus _might_
402 // lie outside the correct interval. 403 // lie outside the correct interval.
403 uint64_t unit = 1; 404 uint64_t unit = 1;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 450 }
450 divisor /= 10; 451 divisor /= 10;
451 } 452 }
452 453
453 // The integrals have been generated. We are at the point of the decimal 454 // The integrals have been generated. We are at the point of the decimal
454 // separator. In the following loop we simply multiply the remaining dig its by 455 // separator. In the following loop we simply multiply the remaining dig its by
455 // 10 and divide by one. We just need to pay attention to multiply assoc iated 456 // 10 and divide by one. We just need to pay attention to multiply assoc iated
456 // data (like the interval or 'unit'), too. 457 // data (like the interval or 'unit'), too.
457 // Note that the multiplication by 10 does not overflow, because w.e >= -60 458 // Note that the multiplication by 10 does not overflow, because w.e >= -60
458 // and thus one.e >= -60. 459 // and thus one.e >= -60.
459 ASSERT(one.E() >= -60); 460 DCHECK_GE(one.E(), -60);
460 ASSERT(fractionals < one.F()); 461 DCHECK_LT(fractionals, one.F());
461 ASSERT(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.F()); 462 DCHECK_GE(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10, one.F());
462 while (true) { 463 while (true) {
463 fractionals *= 10; 464 fractionals *= 10;
464 unit *= 10; 465 unit *= 10;
465 unsafe_interval.set_f(unsafe_interval.F() * 10); 466 unsafe_interval.set_f(unsafe_interval.F() * 10);
466 // Integer division by one. 467 // Integer division by one.
467 char digit = static_cast<char>(fractionals >> -one.E()); 468 char digit = static_cast<char>(fractionals >> -one.E());
468 buffer[*length] = '0' + digit; 469 buffer[*length] = '0' + digit;
469 (*length)++; 470 (*length)++;
470 fractionals &= one.F() - 1; // Modulo by one. 471 fractionals &= one.F() - 1; // Modulo by one.
471 (*kappa)--; 472 (*kappa)--;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 // 506 //
506 // Remark: This procedure takes into account the imprecision of its input 507 // Remark: This procedure takes into account the imprecision of its input
507 // numbers. If the precision is not enough to guarantee all the postcondit ions 508 // numbers. If the precision is not enough to guarantee all the postcondit ions
508 // then false is returned. This usually happens rarely, but the failure-ra te 509 // then false is returned. This usually happens rarely, but the failure-ra te
509 // increases with higher requested_digits. 510 // increases with higher requested_digits.
510 static bool DigitGenCounted(DiyFp w, 511 static bool DigitGenCounted(DiyFp w,
511 int requested_digits, 512 int requested_digits,
512 Vector<char> buffer, 513 Vector<char> buffer,
513 int* length, 514 int* length,
514 int* kappa) { 515 int* kappa) {
515 ASSERT(kMinimalTargetExponent <= w.E() && 516 DCHECK_LE(kMinimalTargetExponent, w.E());
516 w.E() <= kMaximalTargetExponent); 517 DCHECK_LE(w.E(), kMaximalTargetExponent);
517 ASSERT(kMinimalTargetExponent >= -60); 518 DCHECK_GE(kMinimalTargetExponent, -60);
518 ASSERT(kMaximalTargetExponent <= -32); 519 DCHECK_LE(kMaximalTargetExponent, -32);
519 // w is assumed to have an error less than 1 unit. Whenever w is scaled we 520 // w is assumed to have an error less than 1 unit. Whenever w is scaled we
520 // also scale its error. 521 // also scale its error.
521 uint64_t w_error = 1; 522 uint64_t w_error = 1;
522 // We cut the input number into two parts: the integral digits and the 523 // We cut the input number into two parts: the integral digits and the
523 // fractional digits. We don't emit any decimal separator, but adapt kappa 524 // fractional digits. We don't emit any decimal separator, but adapt kappa
524 // instead. Example: instead of writing "1.2" we put "12" into the buffer 525 // instead. Example: instead of writing "1.2" we put "12" into the buffer
525 // and increase kappa by 1. 526 // and increase kappa by 1.
526 DiyFp one = DiyFp(static_cast<uint64_t>(1) << -w.E(), w.E()); 527 DiyFp one = DiyFp(static_cast<uint64_t>(1) << -w.E(), w.E());
527 // Division by one is a shift. 528 // Division by one is a shift.
528 uint32_t integrals = static_cast<uint32_t>(w.F() >> -one.E()); 529 uint32_t integrals = static_cast<uint32_t>(w.F() >> -one.E());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 static_cast<uint64_t>(divisor) << -one.E(), 561 static_cast<uint64_t>(divisor) << -one.E(),
561 w_error, kappa); 562 w_error, kappa);
562 } 563 }
563 564
564 // The integrals have been generated. We are at the point of the decimal 565 // The integrals have been generated. We are at the point of the decimal
565 // separator. In the following loop we simply multiply the remaining dig its by 566 // separator. In the following loop we simply multiply the remaining dig its by
566 // 10 and divide by one. We just need to pay attention to multiply assoc iated 567 // 10 and divide by one. We just need to pay attention to multiply assoc iated
567 // data (the 'unit'), too. 568 // data (the 'unit'), too.
568 // Note that the multiplication by 10 does not overflow, because w.e >= -60 569 // Note that the multiplication by 10 does not overflow, because w.e >= -60
569 // and thus one.e >= -60. 570 // and thus one.e >= -60.
570 ASSERT(one.E() >= -60); 571 DCHECK_GE(one.E(), -60);
571 ASSERT(fractionals < one.F()); 572 DCHECK_LT(fractionals, one.F());
572 ASSERT(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.F()); 573 DCHECK_GE(UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10, one.F());
573 while (requested_digits > 0 && fractionals > w_error) { 574 while (requested_digits > 0 && fractionals > w_error) {
574 fractionals *= 10; 575 fractionals *= 10;
575 w_error *= 10; 576 w_error *= 10;
576 // Integer division by one. 577 // Integer division by one.
577 char digit = static_cast<char>(fractionals >> -one.E()); 578 char digit = static_cast<char>(fractionals >> -one.E());
578 buffer[*length] = '0' + digit; 579 buffer[*length] = '0' + digit;
579 (*length)++; 580 (*length)++;
580 requested_digits--; 581 requested_digits--;
581 fractionals &= one.F() - 1; // Modulo by one. 582 fractionals &= one.F() - 1; // Modulo by one.
582 (*kappa)--; 583 (*kappa)--;
(...skipping 19 matching lines...) Expand all
602 Vector<char> buffer, 603 Vector<char> buffer,
603 int* length, 604 int* length,
604 int* decimal_exponent) { 605 int* decimal_exponent) {
605 DiyFp w = Double(v).AsNormalizedDiyFp(); 606 DiyFp w = Double(v).AsNormalizedDiyFp();
606 // boundary_minus and boundary_plus are the boundaries between v and its 607 // boundary_minus and boundary_plus are the boundaries between v and its
607 // closest floating-point neighbors. Any number strictly between 608 // closest floating-point neighbors. Any number strictly between
608 // boundary_minus and boundary_plus will round to v when convert to a do uble. 609 // boundary_minus and boundary_plus will round to v when convert to a do uble.
609 // Grisu3 will never output representations that lie exactly on a bounda ry. 610 // Grisu3 will never output representations that lie exactly on a bounda ry.
610 DiyFp boundary_minus, boundary_plus; 611 DiyFp boundary_minus, boundary_plus;
611 Double(v).NormalizedBoundaries(&boundary_minus, &boundary_plus); 612 Double(v).NormalizedBoundaries(&boundary_minus, &boundary_plus);
612 ASSERT(boundary_plus.E() == w.E()); 613 DCHECK_EQ(boundary_plus.E(), w.E());
613 DiyFp ten_mk; // Cached power of ten: 10^-k 614 DiyFp ten_mk; // Cached power of ten: 10^-k
614 int mk; // -k 615 int mk; // -k
615 int ten_mk_minimal_binary_exponent = 616 int ten_mk_minimal_binary_exponent =
616 kMinimalTargetExponent - (w.E() + DiyFp::kSignificandSize); 617 kMinimalTargetExponent - (w.E() + DiyFp::kSignificandSize);
617 int ten_mk_maximal_binary_exponent = 618 int ten_mk_maximal_binary_exponent =
618 kMaximalTargetExponent - (w.E() + DiyFp::kSignificandSize); 619 kMaximalTargetExponent - (w.E() + DiyFp::kSignificandSize);
619 PowersOfTenCache::GetCachedPowerForBinaryExponentRange( 620 PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
620 ten_mk_minimal_bi nary_exponent, 621 ten_mk_minimal_bi nary_exponent,
621 ten_mk_maximal_bi nary_exponent, 622 ten_mk_maximal_bi nary_exponent,
622 &ten_mk, &mk); 623 &ten_mk, &mk);
623 ASSERT((kMinimalTargetExponent <= 624 DCHECK_LE(kMinimalTargetExponent,
624 w.E() + ten_mk.E() + DiyFp::kSignificandSize) && 625 w.E() + ten_mk.E() + DiyFp::kSignificandSize);
625 (kMaximalTargetExponent >= 626 DCHECK_GE(kMaximalTargetExponent,
626 w.E() + ten_mk.E() + DiyFp::kSignificandSize)); 627 w.E() + ten_mk.E() + DiyFp::kSignificandSize);
627 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only cont ains a 628 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only cont ains a
628 // 64 bit significand and ten_mk is thus only precise up to 64 bits. 629 // 64 bit significand and ten_mk is thus only precise up to 64 bits.
629 630
630 // The DiyFp::Times procedure rounds its result, and ten_mk is approxima ted 631 // The DiyFp::Times procedure rounds its result, and ten_mk is approxima ted
631 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) ar e now 632 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) ar e now
632 // off by a small amount. 633 // off by a small amount.
633 // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_ w. 634 // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_ w.
634 // In other words: let f = scaled_w.f() and e = scaled_w.e(), then 635 // In other words: let f = scaled_w.f() and e = scaled_w.e(), then
635 // (f-1) * 2^e < w*10^k < (f+1) * 2^e 636 // (f-1) * 2^e < w*10^k < (f+1) * 2^e
636 DiyFp scaled_w = DiyFp::Times(w, ten_mk); 637 DiyFp scaled_w = DiyFp::Times(w, ten_mk);
637 ASSERT(scaled_w.E() == 638 DCHECK_EQ(scaled_w.E(),
638 boundary_plus.E() + ten_mk.E() + DiyFp::kSignificandSize); 639 boundary_plus.E() + ten_mk.E() + DiyFp::kSignificandSize);
639 // In theory it would be possible to avoid some recomputations by comput ing 640 // In theory it would be possible to avoid some recomputations by comput ing
640 // the difference between w and boundary_minus/plus (a power of 2) and t o 641 // the difference between w and boundary_minus/plus (a power of 2) and t o
641 // compute scaled_boundary_minus/plus by subtracting/adding from 642 // compute scaled_boundary_minus/plus by subtracting/adding from
642 // scaled_w. However the code becomes much less readable and the speed 643 // scaled_w. However the code becomes much less readable and the speed
643 // enhancements are not terriffic. 644 // enhancements are not terriffic.
644 DiyFp scaled_boundary_minus = DiyFp::Times(boundary_minus, ten_mk); 645 DiyFp scaled_boundary_minus = DiyFp::Times(boundary_minus, ten_mk);
645 DiyFp scaled_boundary_plus = DiyFp::Times(boundary_plus, ten_mk); 646 DiyFp scaled_boundary_plus = DiyFp::Times(boundary_plus, ten_mk);
646 647
647 // DigitGen will generate the digits of scaled_w. Therefore we have 648 // DigitGen will generate the digits of scaled_w. Therefore we have
648 // v == (double) (scaled_w * 10^-mk). 649 // v == (double) (scaled_w * 10^-mk).
(...skipping 23 matching lines...) Expand all
672 DiyFp ten_mk; // Cached power of ten: 10^-k 673 DiyFp ten_mk; // Cached power of ten: 10^-k
673 int mk; // -k 674 int mk; // -k
674 int ten_mk_minimal_binary_exponent = 675 int ten_mk_minimal_binary_exponent =
675 kMinimalTargetExponent - (w.E() + DiyFp::kSignificandSize); 676 kMinimalTargetExponent - (w.E() + DiyFp::kSignificandSize);
676 int ten_mk_maximal_binary_exponent = 677 int ten_mk_maximal_binary_exponent =
677 kMaximalTargetExponent - (w.E() + DiyFp::kSignificandSize); 678 kMaximalTargetExponent - (w.E() + DiyFp::kSignificandSize);
678 PowersOfTenCache::GetCachedPowerForBinaryExponentRange( 679 PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
679 ten_mk_minimal_bi nary_exponent, 680 ten_mk_minimal_bi nary_exponent,
680 ten_mk_maximal_bi nary_exponent, 681 ten_mk_maximal_bi nary_exponent,
681 &ten_mk, &mk); 682 &ten_mk, &mk);
682 ASSERT((kMinimalTargetExponent <= 683 DCHECK_LE(kMinimalTargetExponent,
683 w.E() + ten_mk.E() + DiyFp::kSignificandSize) && 684 w.E() + ten_mk.E() + DiyFp::kSignificandSize);
684 (kMaximalTargetExponent >= 685 DCHECK_GE(kMaximalTargetExponent,
685 w.E() + ten_mk.E() + DiyFp::kSignificandSize)); 686 w.E() + ten_mk.E() + DiyFp::kSignificandSize);
686 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only cont ains a 687 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only cont ains a
687 // 64 bit significand and ten_mk is thus only precise up to 64 bits. 688 // 64 bit significand and ten_mk is thus only precise up to 64 bits.
688 689
689 // The DiyFp::Times procedure rounds its result, and ten_mk is approxima ted 690 // The DiyFp::Times procedure rounds its result, and ten_mk is approxima ted
690 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) ar e now 691 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) ar e now
691 // off by a small amount. 692 // off by a small amount.
692 // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_ w. 693 // In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_ w.
693 // In other words: let f = scaled_w.f() and e = scaled_w.e(), then 694 // In other words: let f = scaled_w.f() and e = scaled_w.e(), then
694 // (f-1) * 2^e < w*10^k < (f+1) * 2^e 695 // (f-1) * 2^e < w*10^k < (f+1) * 2^e
695 DiyFp scaled_w = DiyFp::Times(w, ten_mk); 696 DiyFp scaled_w = DiyFp::Times(w, ten_mk);
(...skipping 10 matching lines...) Expand all
706 return result; 707 return result;
707 } 708 }
708 709
709 710
710 bool FastDtoa(double v, 711 bool FastDtoa(double v,
711 FastDtoaMode mode, 712 FastDtoaMode mode,
712 int requested_digits, 713 int requested_digits,
713 Vector<char> buffer, 714 Vector<char> buffer,
714 int* length, 715 int* length,
715 int* decimal_point) { 716 int* decimal_point) {
716 ASSERT(v > 0); 717 DCHECK_GT(v, 0);
717 DCHECK(!Double(v).IsSpecial()); 718 DCHECK(!Double(v).IsSpecial());
718 719
719 bool result = false; 720 bool result = false;
720 int decimal_exponent = 0; 721 int decimal_exponent = 0;
721 switch (mode) { 722 switch (mode) {
722 case FAST_DTOA_SHORTEST: 723 case FAST_DTOA_SHORTEST:
723 result = Grisu3(v, buffer, length, &decimal_exponent); 724 result = Grisu3(v, buffer, length, &decimal_exponent);
724 break; 725 break;
725 case FAST_DTOA_PRECISION: 726 case FAST_DTOA_PRECISION:
726 result = Grisu3Counted(v, requested_digits, 727 result = Grisu3Counted(v, requested_digits,
727 buffer, length, &decimal_exponent); 728 buffer, length, &decimal_exponent);
728 break; 729 break;
729 default: 730 default:
730 UNREACHABLE(); 731 UNREACHABLE();
731 } 732 }
732 if (result) { 733 if (result) {
733 *decimal_point = *length + decimal_exponent; 734 *decimal_point = *length + decimal_exponent;
734 buffer[*length] = '\0'; 735 buffer[*length] = '\0';
735 } 736 }
736 return result; 737 return result;
737 } 738 }
738 739
739 } // namespace double_conversion 740 } // namespace double_conversion
740 741
741 } // namespace WTF 742 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698