31
31
// multiplying/dividing the written-out number by 10^9 to get blocks. It's
32
32
// significantly faster than INT_CALC, only about 10x slower than MEGA_TABLE,
33
33
// and is small in binary size. Its downside is that it always calculates all
34
- // of the digits above the decimal point, making it ineffecient for %e calls
35
- // with large exponents. If this flag is not set, no other flags will change
36
- // the long double behavior.
34
+ // of the digits above the decimal point, making it inefficient for %e calls
35
+ // with large exponents. This specialization overrides other flags, so this
36
+ // flag must be set for other flags to effect the long double behavior.
37
37
38
38
// LIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE
39
39
// The Mega Table is ~5 megabytes when compiled. It lists the constants needed
@@ -609,12 +609,12 @@ class FloatToString {
609
609
610
610
LIBC_INLINE constexpr size_t zero_blocks_after_point () {
611
611
#ifdef LIBC_COPT_FLOAT_TO_STR_NO_TABLE
612
- if (exponent < -MANT_WIDTH ) {
612
+ if (exponent < -FRACTION_LEN ) {
613
613
const int pos_exp = -exponent - 1 ;
614
614
const uint32_t pos_idx =
615
615
static_cast <uint32_t >(pos_exp + (IDX_SIZE - 1 )) / IDX_SIZE;
616
616
const int32_t pos_len = ((internal::ceil_log10_pow2 (pos_idx * IDX_SIZE) -
617
- internal::ceil_log10_pow2 (MANT_WIDTH + 1 )) /
617
+ internal::ceil_log10_pow2 (FRACTION_LEN + 1 )) /
618
618
BLOCK_SIZE) -
619
619
1 ;
620
620
const uint32_t len = static_cast <uint32_t >(pos_len > 0 ? pos_len : 0 );
@@ -640,17 +640,15 @@ template <> class FloatToString<long double> {
640
640
static constexpr int FRACTION_LEN = fputil::FPBits<long double >::FRACTION_LEN;
641
641
static constexpr int EXP_BIAS = fputil::FPBits<long double >::EXP_BIAS;
642
642
643
- // static constexpr size_t FLOAT_AS_INT_WIDTH = 16384;
644
643
static constexpr size_t FLOAT_AS_INT_WIDTH =
645
644
internal::div_ceil (fputil::FPBits<long double >::MAX_BIASED_EXPONENT -
646
645
FloatProp::EXP_BIAS,
647
646
64 ) *
648
647
64 ;
649
- // static constexpr size_t EXTRA_INT_WIDTH = 128;
650
648
static constexpr size_t EXTRA_INT_WIDTH =
651
649
internal::div_ceil (sizeof (long double ) * 8 , 64 ) * 64 ;
652
650
653
- cpp::BigInt <FLOAT_AS_INT_WIDTH + EXTRA_INT_WIDTH, false > float_as_int = 0 ;
651
+ cpp::UInt <FLOAT_AS_INT_WIDTH + EXTRA_INT_WIDTH> float_as_int = 0 ;
654
652
int int_block_index = 0 ;
655
653
656
654
static constexpr size_t BLOCK_BUFFER_LEN =
@@ -659,8 +657,7 @@ template <> class FloatToString<long double> {
659
657
size_t block_buffer_valid = 0 ;
660
658
661
659
template <size_t Bits>
662
- LIBC_INLINE static constexpr BlockInt
663
- grab_digits (cpp::BigInt<Bits, false > &int_num) {
660
+ LIBC_INLINE static constexpr BlockInt grab_digits (cpp::UInt<Bits> &int_num) {
664
661
BlockInt cur_block = 0 ;
665
662
auto wide_result = int_num.div_uint32_times_pow_2 (1953125 , 9 );
666
663
// the optional only comes into effect when dividing by 0, which will
@@ -671,8 +668,8 @@ template <> class FloatToString<long double> {
671
668
}
672
669
673
670
LIBC_INLINE static constexpr void zero_leading_digits (
674
- cpp::BigInt <FLOAT_AS_INT_WIDTH + EXTRA_INT_WIDTH, false > &int_num) {
675
- // 64 is the width of the numbers used to internally represent the BigInt
671
+ cpp::UInt <FLOAT_AS_INT_WIDTH + EXTRA_INT_WIDTH> &int_num) {
672
+ // 64 is the width of the numbers used to internally represent the UInt
676
673
for (size_t i = 0 ; i < EXTRA_INT_WIDTH / 64 ; ++i) {
677
674
int_num[i + (FLOAT_AS_INT_WIDTH / 64 )] = 0 ;
678
675
}
@@ -703,7 +700,7 @@ template <> class FloatToString<long double> {
703
700
block_buffer_valid = int_block_index;
704
701
705
702
} else {
706
- // if the exponent not positive, then the number is at least partially
703
+ // if the exponent is not positive, then the number is at least partially
707
704
// below the decimal point. Shift left to make the int a fixed point
708
705
// representation with the decimal point after the top EXTRA_INT_WIDTH
709
706
// bits.
@@ -713,7 +710,7 @@ template <> class FloatToString<long double> {
713
710
714
711
// If there are still digits above the decimal point, handle those.
715
712
if (float_as_int.clz () < EXTRA_INT_WIDTH) {
716
- cpp::BigInt <EXTRA_INT_WIDTH, false > above_decimal_point =
713
+ cpp::UInt <EXTRA_INT_WIDTH> above_decimal_point =
717
714
float_as_int >> FLOAT_AS_INT_WIDTH;
718
715
719
716
size_t positive_int_block_index = 0 ;
@@ -810,7 +807,7 @@ template <> class FloatToString<long double> {
810
807
int block_index = -1 - negative_block_index;
811
808
812
809
// If we're currently after the requested block (remember these are
813
- // negative indices) the reset the number to the start. This is only
810
+ // negative indices) we reset the number to the start. This is only
814
811
// likely to happen in %g calls. This will also reset int_block_index.
815
812
if (block_index > int_block_index) {
816
813
init_convert ();
0 commit comments