File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,11 @@ namespace LIBC_NAMESPACE::cpp {
27
27
28
28
template <size_t Bits, bool Signed> struct BigInt {
29
29
30
+ // This being hardcoded as 64 is okay because we're using uint64_t as our
31
+ // internal type which will always be 64 bits.
32
+ LIBC_INLINE_VAR static constexpr size_t WORD_SIZE = 64 ;
33
+
34
+ // TODO: Replace references to 64 with WORD_SIZE.
30
35
static_assert (Bits > 0 && Bits % 64 == 0 ,
31
36
" Number of bits in BigInt should be a multiple of 64." );
32
37
LIBC_INLINE_VAR static constexpr size_t WORDCOUNT = Bits / 64 ;
Original file line number Diff line number Diff line change @@ -670,8 +670,8 @@ template <> class FloatToString<long double> {
670
670
LIBC_INLINE static constexpr void zero_leading_digits (
671
671
cpp::UInt<FLOAT_AS_INT_WIDTH + EXTRA_INT_WIDTH> &int_num) {
672
672
// 64 is the width of the numbers used to internally represent the UInt
673
- for (size_t i = 0 ; i < EXTRA_INT_WIDTH / 64 ; ++i) {
674
- int_num[i + (FLOAT_AS_INT_WIDTH / 64 )] = 0 ;
673
+ for (size_t i = 0 ; i < EXTRA_INT_WIDTH / int_num. WORD_SIZE ; ++i) {
674
+ int_num[i + (FLOAT_AS_INT_WIDTH / int_num. WORD_SIZE )] = 0 ;
675
675
}
676
676
}
677
677
@@ -809,10 +809,14 @@ template <> class FloatToString<long double> {
809
809
// If we're currently after the requested block (remember these are
810
810
// negative indices) we reset the number to the start. This is only
811
811
// likely to happen in %g calls. This will also reset int_block_index.
812
- if (block_index > int_block_index) {
813
- init_convert ();
814
- }
815
-
812
+ // if (block_index > int_block_index) {
813
+ // init_convert();
814
+ // }
815
+
816
+ // Printf is the only existing user of this code and it will only ever move
817
+ // downwards, except for %g but that currently creates a second
818
+ // float_to_string object so this assertion still holds. If a new user needs
819
+ // the ability to step backwards, uncomment the code above.
816
820
LIBC_ASSERT (block_index <= int_block_index);
817
821
818
822
// If we are currently before the requested block. Step until we reach the
Original file line number Diff line number Diff line change @@ -2985,6 +2985,9 @@ TEST_F(LlvmLibcSPrintfTest, FloatAutoLongDoubleConv) {
2985
2985
written = LIBC_NAMESPACE::sprintf (buff, " %Lg" , 0xa .aaaaaaaaaaaaaabp -7L );
2986
2986
ASSERT_STREQ_LEN (written, buff, " 0.0833333" );
2987
2987
2988
+ written = LIBC_NAMESPACE::sprintf (buff, " %Lg" , 9 .99999999999e-100L );
2989
+ ASSERT_STREQ_LEN (written, buff, " 1e-99" );
2990
+
2988
2991
#endif // LIBC_LONG_DOUBLE_IS_X86_FLOAT80
2989
2992
2990
2993
// TODO: Uncomment the below tests after long double support is added
You can’t perform that action at this time.
0 commit comments