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

Side by Side Diff: src/fast-dtoa.cc

Issue 3608011: Simplify powers-of-ten cache. (Closed)
Patch Set: Created 10 years, 2 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
« no previous file with comments | « src/cached-powers.cc ('k') | src/powers-ten.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 DiyFp w = Double(v).AsNormalizedDiyFp(); 602 DiyFp w = Double(v).AsNormalizedDiyFp();
603 // boundary_minus and boundary_plus are the boundaries between v and its 603 // boundary_minus and boundary_plus are the boundaries between v and its
604 // closest floating-point neighbors. Any number strictly between 604 // closest floating-point neighbors. Any number strictly between
605 // boundary_minus and boundary_plus will round to v when convert to a double. 605 // boundary_minus and boundary_plus will round to v when convert to a double.
606 // Grisu3 will never output representations that lie exactly on a boundary. 606 // Grisu3 will never output representations that lie exactly on a boundary.
607 DiyFp boundary_minus, boundary_plus; 607 DiyFp boundary_minus, boundary_plus;
608 Double(v).NormalizedBoundaries(&boundary_minus, &boundary_plus); 608 Double(v).NormalizedBoundaries(&boundary_minus, &boundary_plus);
609 ASSERT(boundary_plus.e() == w.e()); 609 ASSERT(boundary_plus.e() == w.e());
610 DiyFp ten_mk; // Cached power of ten: 10^-k 610 DiyFp ten_mk; // Cached power of ten: 10^-k
611 int mk; // -k 611 int mk; // -k
612 GetCachedPower(w.e() + DiyFp::kSignificandSize, kMinimalTargetExponent, 612 int ten_mk_minimal_binary_exponent =
613 kMaximalTargetExponent, &mk, &ten_mk); 613 kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize);
614 int ten_mk_maximal_binary_exponent =
615 kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize);
616 GetCachedPowerForBinaryExponentRange(ten_mk_minimal_binary_exponent,
617 ten_mk_maximal_binary_exponent,
618 &ten_mk, &mk);
614 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + 619 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() +
615 DiyFp::kSignificandSize) && 620 DiyFp::kSignificandSize) &&
616 (kMaximalTargetExponent >= w.e() + ten_mk.e() + 621 (kMaximalTargetExponent >= w.e() + ten_mk.e() +
617 DiyFp::kSignificandSize)); 622 DiyFp::kSignificandSize));
618 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a 623 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a
619 // 64 bit significand and ten_mk is thus only precise up to 64 bits. 624 // 64 bit significand and ten_mk is thus only precise up to 64 bits.
620 625
621 // The DiyFp::Times procedure rounds its result, and ten_mk is approximated 626 // The DiyFp::Times procedure rounds its result, and ten_mk is approximated
622 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now 627 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now
623 // off by a small amount. 628 // off by a small amount.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 // Grisu3 is too imprecise for real halfway cases (1.5 will not work) and 660 // Grisu3 is too imprecise for real halfway cases (1.5 will not work) and
656 // therefore the rounding strategy for halfway cases is irrelevant. 661 // therefore the rounding strategy for halfway cases is irrelevant.
657 static bool Grisu3Counted(double v, 662 static bool Grisu3Counted(double v,
658 int requested_digits, 663 int requested_digits,
659 Vector<char> buffer, 664 Vector<char> buffer,
660 int* length, 665 int* length,
661 int* decimal_exponent) { 666 int* decimal_exponent) {
662 DiyFp w = Double(v).AsNormalizedDiyFp(); 667 DiyFp w = Double(v).AsNormalizedDiyFp();
663 DiyFp ten_mk; // Cached power of ten: 10^-k 668 DiyFp ten_mk; // Cached power of ten: 10^-k
664 int mk; // -k 669 int mk; // -k
665 GetCachedPower(w.e() + DiyFp::kSignificandSize, kMinimalTargetExponent, 670 int ten_mk_minimal_binary_exponent =
666 kMaximalTargetExponent, &mk, &ten_mk); 671 kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize);
672 int ten_mk_maximal_binary_exponent =
673 kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize);
674 GetCachedPowerForBinaryExponentRange(ten_mk_minimal_binary_exponent,
675 ten_mk_maximal_binary_exponent,
676 &ten_mk, &mk);
667 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + 677 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() +
668 DiyFp::kSignificandSize) && 678 DiyFp::kSignificandSize) &&
669 (kMaximalTargetExponent >= w.e() + ten_mk.e() + 679 (kMaximalTargetExponent >= w.e() + ten_mk.e() +
670 DiyFp::kSignificandSize)); 680 DiyFp::kSignificandSize));
671 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a 681 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a
672 // 64 bit significand and ten_mk is thus only precise up to 64 bits. 682 // 64 bit significand and ten_mk is thus only precise up to 64 bits.
673 683
674 // The DiyFp::Times procedure rounds its result, and ten_mk is approximated 684 // The DiyFp::Times procedure rounds its result, and ten_mk is approximated
675 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now 685 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now
676 // off by a small amount. 686 // off by a small amount.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 UNREACHABLE(); 725 UNREACHABLE();
716 } 726 }
717 if (result) { 727 if (result) {
718 *decimal_point = *length + decimal_exponent; 728 *decimal_point = *length + decimal_exponent;
719 buffer[*length] = '\0'; 729 buffer[*length] = '\0';
720 } 730 }
721 return result; 731 return result;
722 } 732 }
723 733
724 } } // namespace v8::internal 734 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/cached-powers.cc ('k') | src/powers-ten.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698