Skip to content

Commit 805e09b

Browse files
clean up code style
1 parent 4233caf commit 805e09b

File tree

1 file changed

+33
-48
lines changed

1 file changed

+33
-48
lines changed

libc/src/__support/float_to_string.h

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,7 @@ class FloatToString {
617617
internal::ceil_log10_pow2(FRACTION_LEN + 1)) /
618618
BLOCK_SIZE) -
619619
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);
622621
}
623622
return 0;
624623
#else
@@ -661,18 +660,17 @@ template <> class FloatToString<long double> {
661660

662661
template <size_t Bits>
663662
LIBC_INLINE static constexpr BlockInt grab_digits(cpp::UInt<Bits> &int_num) {
664-
BlockInt cur_block = 0;
665663
auto wide_result = int_num.div_uint32_times_pow_2(1953125, 9);
666664
// the optional only comes into effect when dividing by 0, which will
667665
// never happen here. Thus, we just assert that it has value.
668666
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());
671668
}
672669

673670
LIBC_INLINE static constexpr void zero_leading_digits(
674671
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
676674
for (size_t i = 0; i < EXTRA_INT_WIDTH / int_num.WORD_SIZE; ++i) {
677675
int_num[i + (FLOAT_AS_INT_WIDTH / int_num.WORD_SIZE)] = 0;
678676
}
@@ -683,9 +681,8 @@ template <> class FloatToString<long double> {
683681
// return the class to the starting state.
684682
LIBC_INLINE constexpr void init_convert() {
685683
// No calculation necessary for the 0 case.
686-
if (mantissa == 0 && exponent == 0) {
684+
if (mantissa == 0 && exponent == 0)
687685
return;
688-
}
689686

690687
if (exponent > 0) {
691688
// if the exponent is positive, then the number is fully above the decimal
@@ -701,8 +698,7 @@ template <> class FloatToString<long double> {
701698
int_block_index = 0;
702699

703700
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);
706702
++int_block_index;
707703
}
708704
block_buffer_valid = int_block_index;
@@ -724,8 +720,8 @@ template <> class FloatToString<long double> {
724720

725721
size_t positive_int_block_index = 0;
726722
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);
729725
++positive_int_block_index;
730726
}
731727
block_buffer_valid = positive_int_block_index;
@@ -751,36 +747,31 @@ template <> class FloatToString<long double> {
751747
}
752748

753749
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)
763751
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);
765758
}
766759

767760
LIBC_INLINE constexpr size_t zero_blocks_after_point() {
768761
#ifdef LIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE
769762
return MIN_BLOCK_2[-exponent / IDX_SIZE];
770763
#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;
783766

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);
784775
#endif
785776
}
786777

@@ -794,20 +785,17 @@ template <> class FloatToString<long double> {
794785
}
795786

796787
LIBC_INLINE constexpr BlockInt get_positive_block(int block_index) {
797-
if (exponent < -FRACTION_LEN) {
788+
if (exponent < -FRACTION_LEN)
798789
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)
801791
return 0;
802-
}
803792

804793
return block_buffer[block_index];
805794
}
806795

807796
LIBC_INLINE constexpr BlockInt get_negative_block(int negative_block_index) {
808-
if (exponent >= 0) {
797+
if (exponent >= 0)
809798
return 0;
810-
}
811799

812800
// negative_block_index starts at 0 with the first block after the decimal
813801
// point, and 1 with the second and so on. This converts to the same
@@ -836,18 +824,15 @@ template <> class FloatToString<long double> {
836824
--int_block_index;
837825
}
838826

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);
843829
}
844830

845831
LIBC_INLINE constexpr BlockInt get_block(int block_index) {
846-
if (block_index >= 0) {
832+
if (block_index >= 0)
847833
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);
851836
}
852837
};
853838

0 commit comments

Comments
 (0)