@@ -617,8 +617,7 @@ class FloatToString {
617
617
internal::ceil_log10_pow2 (FRACTION_LEN + 1 )) /
618
618
BLOCK_SIZE) -
619
619
1 ;
620
- const uint32_t len = static_cast <uint32_t >(pos_len > 0 ? pos_len : 0 );
621
- return len;
620
+ return len = static_cast <uint32_t >(pos_len > 0 ? pos_len : 0 );
622
621
}
623
622
return 0 ;
624
623
#else
@@ -661,18 +660,17 @@ template <> class FloatToString<long double> {
661
660
662
661
template <size_t Bits>
663
662
LIBC_INLINE static constexpr BlockInt grab_digits (cpp::UInt<Bits> &int_num) {
664
- BlockInt cur_block = 0 ;
665
663
auto wide_result = int_num.div_uint32_times_pow_2 (1953125 , 9 );
666
664
// the optional only comes into effect when dividing by 0, which will
667
665
// never happen here. Thus, we just assert that it has value.
668
666
LIBC_ASSERT (wide_result.has_value ());
669
- cur_block = static_cast <BlockInt>(wide_result.value ());
670
- return cur_block;
667
+ return static_cast <BlockInt>(wide_result.value ());
671
668
}
672
669
673
670
LIBC_INLINE static constexpr void zero_leading_digits (
674
671
cpp::UInt<FLOAT_AS_INT_WIDTH + EXTRA_INT_WIDTH> &int_num) {
675
- // 64 is the width of the numbers used to internally represent the UInt
672
+ // WORD_SIZE is the width of the numbers used to internally represent the
673
+ // UInt
676
674
for (size_t i = 0 ; i < EXTRA_INT_WIDTH / int_num.WORD_SIZE ; ++i) {
677
675
int_num[i + (FLOAT_AS_INT_WIDTH / int_num.WORD_SIZE )] = 0 ;
678
676
}
@@ -683,9 +681,8 @@ template <> class FloatToString<long double> {
683
681
// return the class to the starting state.
684
682
LIBC_INLINE constexpr void init_convert () {
685
683
// No calculation necessary for the 0 case.
686
- if (mantissa == 0 && exponent == 0 ) {
684
+ if (mantissa == 0 && exponent == 0 )
687
685
return ;
688
- }
689
686
690
687
if (exponent > 0 ) {
691
688
// if the exponent is positive, then the number is fully above the decimal
@@ -701,8 +698,7 @@ template <> class FloatToString<long double> {
701
698
int_block_index = 0 ;
702
699
703
700
while (float_as_int > 0 ) {
704
- BlockInt cur_block = grab_digits (float_as_int);
705
- block_buffer[int_block_index] = cur_block;
701
+ block_buffer[int_block_index] = grab_digits (float_as_int);
706
702
++int_block_index;
707
703
}
708
704
block_buffer_valid = int_block_index;
@@ -724,8 +720,8 @@ template <> class FloatToString<long double> {
724
720
725
721
size_t positive_int_block_index = 0 ;
726
722
while (above_decimal_point > 0 ) {
727
- BlockInt cur_block = grab_digits (above_decimal_point);
728
- block_buffer[positive_int_block_index] = cur_block ;
723
+ block_buffer[positive_int_block_index] =
724
+ grab_digits (above_decimal_point) ;
729
725
++positive_int_block_index;
730
726
}
731
727
block_buffer_valid = positive_int_block_index;
@@ -751,36 +747,31 @@ template <> class FloatToString<long double> {
751
747
}
752
748
753
749
LIBC_INLINE constexpr size_t get_positive_blocks () {
754
- if (exponent >= -FRACTION_LEN) {
755
- const uint32_t idx =
756
- exponent < 0
757
- ? 0
758
- : static_cast <uint32_t >(exponent + (IDX_SIZE - 1 )) / IDX_SIZE;
759
- const uint32_t len =
760
- internal::length_for_num (idx * IDX_SIZE, FRACTION_LEN);
761
- return len;
762
- } else {
750
+ if (exponent < -FRACTION_LEN)
763
751
return 0 ;
764
- }
752
+
753
+ const uint32_t idx =
754
+ exponent < 0
755
+ ? 0
756
+ : static_cast <uint32_t >(exponent + (IDX_SIZE - 1 )) / IDX_SIZE;
757
+ return internal::length_for_num (idx * IDX_SIZE, FRACTION_LEN);
765
758
}
766
759
767
760
LIBC_INLINE constexpr size_t zero_blocks_after_point () {
768
761
#ifdef LIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE
769
762
return MIN_BLOCK_2[-exponent / IDX_SIZE];
770
763
#else
771
- if (exponent < -FRACTION_LEN) {
772
- const int pos_exp = -exponent - 1 ;
773
- const uint32_t pos_idx =
774
- static_cast <uint32_t >(pos_exp + (IDX_SIZE - 1 )) / IDX_SIZE;
775
- const int32_t pos_len = ((internal::ceil_log10_pow2 (pos_idx * IDX_SIZE) -
776
- internal::ceil_log10_pow2 (FRACTION_LEN + 1 )) /
777
- BLOCK_SIZE) -
778
- 1 ;
779
- const uint32_t len = static_cast <uint32_t >(pos_len > 0 ? pos_len : 0 );
780
- return len;
781
- }
782
- return 0 ;
764
+ if (exponent >= -FRACTION_LEN)
765
+ return 0 ;
783
766
767
+ const int pos_exp = -exponent - 1 ;
768
+ const uint32_t pos_idx =
769
+ static_cast <uint32_t >(pos_exp + (IDX_SIZE - 1 )) / IDX_SIZE;
770
+ const int32_t pos_len = ((internal::ceil_log10_pow2 (pos_idx * IDX_SIZE) -
771
+ internal::ceil_log10_pow2 (FRACTION_LEN + 1 )) /
772
+ BLOCK_SIZE) -
773
+ 1 ;
774
+ return static_cast <uint32_t >(pos_len > 0 ? pos_len : 0 );
784
775
#endif
785
776
}
786
777
@@ -794,20 +785,17 @@ template <> class FloatToString<long double> {
794
785
}
795
786
796
787
LIBC_INLINE constexpr BlockInt get_positive_block (int block_index) {
797
- if (exponent < -FRACTION_LEN) {
788
+ if (exponent < -FRACTION_LEN)
798
789
return 0 ;
799
- }
800
- if (block_index > static_cast <int >(block_buffer_valid) || block_index < 0 ) {
790
+ if (block_index > static_cast <int >(block_buffer_valid) || block_index < 0 )
801
791
return 0 ;
802
- }
803
792
804
793
return block_buffer[block_index];
805
794
}
806
795
807
796
LIBC_INLINE constexpr BlockInt get_negative_block (int negative_block_index) {
808
- if (exponent >= 0 ) {
797
+ if (exponent >= 0 )
809
798
return 0 ;
810
- }
811
799
812
800
// negative_block_index starts at 0 with the first block after the decimal
813
801
// point, and 1 with the second and so on. This converts to the same
@@ -836,18 +824,15 @@ template <> class FloatToString<long double> {
836
824
--int_block_index;
837
825
}
838
826
839
- // We're currently on the requested block, return the current block.
840
- BlockInt cur_block =
841
- static_cast <BlockInt>(float_as_fixed >> FLOAT_AS_INT_WIDTH);
842
- return cur_block;
827
+ // We're now on the requested block, return the current block.
828
+ return static_cast <BlockInt>(float_as_fixed >> FLOAT_AS_INT_WIDTH);
843
829
}
844
830
845
831
LIBC_INLINE constexpr BlockInt get_block (int block_index) {
846
- if (block_index >= 0 ) {
832
+ if (block_index >= 0 )
847
833
return get_positive_block (block_index);
848
- } else {
849
- return get_negative_block (-1 - block_index);
850
- }
834
+
835
+ return get_negative_block (-1 - block_index);
851
836
}
852
837
};
853
838
0 commit comments