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 GetCachedPowerForBinaryExponentRange(ten_mk_minimal_binary_exponent, | 616 PowersOfTenCache::GetCachedPowerForBinaryExponentRange( |
617 ten_mk_maximal_binary_exponent, | 617 ten_mk_minimal_binary_exponent, |
618 &ten_mk, &mk); | 618 ten_mk_maximal_binary_exponent, |
| 619 &ten_mk, &mk); |
619 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + | 620 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + |
620 DiyFp::kSignificandSize) && | 621 DiyFp::kSignificandSize) && |
621 (kMaximalTargetExponent >= w.e() + ten_mk.e() + | 622 (kMaximalTargetExponent >= w.e() + ten_mk.e() + |
622 DiyFp::kSignificandSize)); | 623 DiyFp::kSignificandSize)); |
623 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a | 624 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a |
624 // 64 bit significand and ten_mk is thus only precise up to 64 bits. | 625 // 64 bit significand and ten_mk is thus only precise up to 64 bits. |
625 | 626 |
626 // The DiyFp::Times procedure rounds its result, and ten_mk is approximated | 627 // The DiyFp::Times procedure rounds its result, and ten_mk is approximated |
627 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now | 628 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now |
628 // off by a small amount. | 629 // off by a small amount. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 Vector<char> buffer, | 665 Vector<char> buffer, |
665 int* length, | 666 int* length, |
666 int* decimal_exponent) { | 667 int* decimal_exponent) { |
667 DiyFp w = Double(v).AsNormalizedDiyFp(); | 668 DiyFp w = Double(v).AsNormalizedDiyFp(); |
668 DiyFp ten_mk; // Cached power of ten: 10^-k | 669 DiyFp ten_mk; // Cached power of ten: 10^-k |
669 int mk; // -k | 670 int mk; // -k |
670 int ten_mk_minimal_binary_exponent = | 671 int ten_mk_minimal_binary_exponent = |
671 kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize); | 672 kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize); |
672 int ten_mk_maximal_binary_exponent = | 673 int ten_mk_maximal_binary_exponent = |
673 kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize); | 674 kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize); |
674 GetCachedPowerForBinaryExponentRange(ten_mk_minimal_binary_exponent, | 675 PowersOfTenCache::GetCachedPowerForBinaryExponentRange( |
675 ten_mk_maximal_binary_exponent, | 676 ten_mk_minimal_binary_exponent, |
676 &ten_mk, &mk); | 677 ten_mk_maximal_binary_exponent, |
| 678 &ten_mk, &mk); |
677 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + | 679 ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() + |
678 DiyFp::kSignificandSize) && | 680 DiyFp::kSignificandSize) && |
679 (kMaximalTargetExponent >= w.e() + ten_mk.e() + | 681 (kMaximalTargetExponent >= w.e() + ten_mk.e() + |
680 DiyFp::kSignificandSize)); | 682 DiyFp::kSignificandSize)); |
681 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a | 683 // Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a |
682 // 64 bit significand and ten_mk is thus only precise up to 64 bits. | 684 // 64 bit significand and ten_mk is thus only precise up to 64 bits. |
683 | 685 |
684 // The DiyFp::Times procedure rounds its result, and ten_mk is approximated | 686 // The DiyFp::Times procedure rounds its result, and ten_mk is approximated |
685 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now | 687 // too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now |
686 // off by a small amount. | 688 // off by a small amount. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 UNREACHABLE(); | 727 UNREACHABLE(); |
726 } | 728 } |
727 if (result) { | 729 if (result) { |
728 *decimal_point = *length + decimal_exponent; | 730 *decimal_point = *length + decimal_exponent; |
729 buffer[*length] = '\0'; | 731 buffer[*length] = '\0'; |
730 } | 732 } |
731 return result; | 733 return result; |
732 } | 734 } |
733 | 735 |
734 } } // namespace v8::internal | 736 } } // namespace v8::internal |
OLD | NEW |