Fix for double formatting with precision > 9 (#480)

* Add a test that reproduces the double formatting failure

* Fix root cause, restrict precision to 9 on 32 bit platforms, unrestricted on 64 bit
This commit is contained in:
John Wellbelove 2021-12-15 19:26:17 +00:00
parent 36782f77c0
commit 6f6ebe456b
2 changed files with 9 additions and 9 deletions

View File

@ -270,11 +270,11 @@ namespace etl
//***************************************************************************
template <typename TIString>
void add_integral_and_fractional(const uint64_t integral,
const uint64_t fractional,
TIString& str,
const etl::basic_format_spec<TIString>& integral_format,
const etl::basic_format_spec<TIString>& fractional_format,
const bool negative)
const uint64_t fractional,
TIString& str,
const etl::basic_format_spec<TIString>& integral_format,
const etl::basic_format_spec<TIString>& fractional_format,
const bool negative)
{
typedef typename TIString::value_type type;

View File

@ -598,15 +598,15 @@ namespace
}
//*************************************************************************
TEST(test_double_formatting_10_decimal_point)
TEST(test_double_formatting_15_decimal_point)
{
etl::string<20> result_d;
double value_d = 1.2345;
double value_d = 1.234567890123456;
Format format = Format().precision(10);
Format format = Format().precision(15);
etl::to_string(value_d, result_d, format);
CHECK_EQUAL(etl::string<20>(STR("1.2345000000")).c_str(), result_d.c_str());
CHECK_EQUAL(etl::string<20>(STR("1.234567890123456")).c_str(), result_d.c_str());
}
//*************************************************************************