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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 int ten_mk_minimal_binary_exponent = | 612 int ten_mk_minimal_binary_exponent = |
613 kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize); | 613 kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize); |
614 int ten_mk_maximal_binary_exponent = | 614 int ten_mk_maximal_binary_exponent = |
615 kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize); | 615 kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize); |
616 PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 616 GetCachedPowerForBinaryExponentRange(ten_mk_minimal_binary_exponent, |
617 ten_mk_minimal_binary_exponent, | 617 ten_mk_maximal_binary_exponent, |
618 ten_mk_maximal_binary_exponent, | 618 &ten_mk, &mk); |
619 &ten_mk, &mk); | |
620 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + | 619 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + |
621 DiyFp::kSignificandSize) && | 620 DiyFp::kSignificandSize) && |
622 (kMaximalTargetExponent >= w.e() + ten_mk.e() + | 621 (kMaximalTargetExponent >= w.e() + ten_mk.e() + |
623 DiyFp::kSignificandSize)); | 622 DiyFp::kSignificandSize)); |
624 // 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 |
625 // 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. |
626 | 625 |
627 // 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 |
628 // 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 |
629 // off by a small amount. | 628 // off by a small amount. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 Vector<char> buffer, | 664 Vector<char> buffer, |
666 int* length, | 665 int* length, |
667 int* decimal_exponent) { | 666 int* decimal_exponent) { |
668 DiyFp w = Double(v).AsNormalizedDiyFp(); | 667 DiyFp w = Double(v).AsNormalizedDiyFp(); |
669 DiyFp ten_mk; // Cached power of ten: 10^-k | 668 DiyFp ten_mk; // Cached power of ten: 10^-k |
670 int mk; // -k | 669 int mk; // -k |
671 int ten_mk_minimal_binary_exponent = | 670 int ten_mk_minimal_binary_exponent = |
672 kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize); | 671 kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize); |
673 int ten_mk_maximal_binary_exponent = | 672 int ten_mk_maximal_binary_exponent = |
674 kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize); | 673 kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize); |
675 PowersOfTenCache::GetCachedPowerForBinaryExponentRange( | 674 GetCachedPowerForBinaryExponentRange(ten_mk_minimal_binary_exponent, |
676 ten_mk_minimal_binary_exponent, | 675 ten_mk_maximal_binary_exponent, |
677 ten_mk_maximal_binary_exponent, | 676 &ten_mk, &mk); |
678 &ten_mk, &mk); | |
679 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + | 677 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + |
680 DiyFp::kSignificandSize) && | 678 DiyFp::kSignificandSize) && |
681 (kMaximalTargetExponent >= w.e() + ten_mk.e() + | 679 (kMaximalTargetExponent >= w.e() + ten_mk.e() + |
682 DiyFp::kSignificandSize)); | 680 DiyFp::kSignificandSize)); |
683 // 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 |
684 // 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. |
685 | 683 |
686 // 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 |
687 // 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 |
688 // off by a small amount. | 686 // off by a small amount. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 UNREACHABLE(); | 725 UNREACHABLE(); |
728 } | 726 } |
729 if (result) { | 727 if (result) { |
730 *decimal_point = *length + decimal_exponent; | 728 *decimal_point = *length + decimal_exponent; |
731 buffer[*length] = '\0'; | 729 buffer[*length] = '\0'; |
732 } | 730 } |
733 return result; | 731 return result; |
734 } | 732 } |
735 | 733 |
736 } } // namespace v8::internal | 734 } } // namespace v8::internal |
OLD | NEW |