@@ -1782,10 +1782,19 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
1782
1782
}
1783
1783
1784
1784
const auto initial_digits = static_cast <std::uint32_t >(prod >> 32 );
1785
- decimal_exponent += (11 - (initial_digits < 10 ? 1 : 0 ) + remaining_digits_in_the_current_subsegment);
1785
+ const auto exp_adjustment = 11 - (initial_digits < 10 ? 1 : 0 );
1786
+ decimal_exponent += exp_adjustment + remaining_digits_in_the_current_subsegment;
1787
+ if (fmt == chars_format::fixed && decimal_exponent < 0 )
1788
+ {
1789
+ remaining_digits += decimal_exponent;
1790
+ remaining_digits -= initial_digits < 10 ? 0 : 1 ;
1791
+ }
1792
+ else
1793
+ {
1794
+ remaining_digits -= (2 - (initial_digits < 10 ? 1 : 0 ));
1795
+ }
1786
1796
1787
1797
buffer -= (initial_digits < 10 ? 1 : 0 );
1788
- remaining_digits -= (2 - (initial_digits < 10 ? 1 : 0 ));
1789
1798
print_2_digits (initial_digits, buffer);
1790
1799
buffer += 2 ;
1791
1800
@@ -3841,34 +3850,12 @@ BOOST_CHARCONV_SAFEBUFFERS to_chars_result floff(const double x, const int preci
3841
3850
// Need to memset leading zeros equal to a negative exponent
3842
3851
if (decimal_exponent < 0 )
3843
3852
{
3844
- std::memmove (&buffer_starting_pos[1 - decimal_exponent], &buffer_starting_pos[1 ],
3845
- static_cast <std::size_t >(buffer - buffer_starting_pos + decimal_exponent + 1 ));
3846
- std::memset (&buffer_starting_pos[0 ], ' 0' , static_cast <std::size_t >(-decimal_exponent) + 1U );
3853
+ const auto offset = static_cast <std::size_t >(buffer - buffer_starting_pos);
3854
+ std::size_t additional_zeros = static_cast <std::size_t >(-decimal_exponent) + 1U ;
3855
+ std::memmove (&buffer_starting_pos[1 - decimal_exponent], &buffer_starting_pos[1 ], offset);
3856
+ std::memset (&buffer_starting_pos[0 ], ' 0' , additional_zeros);
3847
3857
buffer_starting_pos[1 ] = ' .' ;
3848
-
3849
- char * const buffer_end = buffer + 1 ;
3850
-
3851
- // Fix the rounding since we are truncating
3852
- if (*(buffer + 1 ) >= ' 5' && *(buffer + 1 ) <= ' 9' )
3853
- {
3854
- if (*buffer != ' 9' )
3855
- {
3856
- *buffer += static_cast <char >(1 );
3857
- --buffer;
3858
- }
3859
- else
3860
- {
3861
- *buffer = ' 0' ;
3862
- --buffer;
3863
- while (*buffer == ' 9' )
3864
- {
3865
- *buffer-- = 0 ;
3866
- }
3867
- *buffer += static_cast <char >(1 );
3868
- }
3869
- }
3870
-
3871
- return {buffer_end, std::errc ()};
3858
+ return {first + precision + 3 , std::errc ()};
3872
3859
}
3873
3860
3874
3861
// In the positive case the precision is still measured after the decimal point
0 commit comments