Merge remote-tracking branch 'origin/feature/to_string' into development

This commit is contained in:
John Wellbelove 2019-04-16 18:08:26 +01:00
commit b926321da6
7 changed files with 66 additions and 9 deletions

View File

@ -201,16 +201,17 @@ namespace etl
void add_integral_fractional(const int64_t integral,
const int64_t fractional,
TIString& str,
const etl::basic_format_spec<TIString>& format)
const etl::basic_format_spec<TIString>& integral_format,
const etl::basic_format_spec<TIString>& fractional_format)
{
typedef typename TIString::value_type type;
etl::private_to_string::add_integral(integral, str, format, true);
etl::private_to_string::add_integral(integral, str, integral_format, true);
if (format.get_precision() > 0)
if (fractional_format.get_precision() > 0)
{
str.push_back(type('.'));
etl::private_to_string::add_integral(fractional, str, format, true);
etl::private_to_string::add_integral(fractional, str, fractional_format, true);
}
}
@ -224,6 +225,7 @@ namespace etl
const bool append)
{
typedef typename TIString::iterator iterator;
typedef typename TIString::value_type type;
if (!append)
{
@ -241,12 +243,15 @@ namespace etl
// Make sure we format the two halves correctly.
uint32_t max_precision = std::numeric_limits<T>::digits10;
etl::basic_format_spec<TIString> local_format = format;
local_format.decimal().width(0).precision(format.get_precision() > max_precision ? max_precision : format.get_precision());
etl::basic_format_spec<TIString> integral_format = format;
integral_format.decimal().width(0).precision(format.get_precision() > max_precision ? max_precision : format.get_precision());
etl::basic_format_spec<TIString> fractional_format = integral_format;
fractional_format.width(integral_format.get_precision()).fill(type('0')).right();
int64_t multiplier = 1;
for (uint32_t i = 0; i < local_format.get_precision(); ++i)
for (uint32_t i = 0; i < fractional_format.get_precision(); ++i)
{
multiplier *= 10U;
}
@ -255,7 +260,7 @@ namespace etl
int64_t integral = static_cast<int64_t>(f_integral);
int64_t fractional = static_cast<int64_t>(round((value - f_integral) * multiplier));
etl::private_to_string::add_integral_fractional(integral, fractional, str, local_format);
etl::private_to_string::add_integral_fractional(integral, fractional, str, integral_format, fractional_format);
}
etl::private_to_string::add_alignment(str, start, format);

View File

@ -39,7 +39,7 @@ SOFTWARE.
#define ETL_VERSION_MAJOR 14
#define ETL_VERSION_MINOR 18
#define ETL_VERSION_PATCH 2
#define ETL_VERSION_PATCH 4
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH)
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH))

View File

@ -1,3 +1,7 @@
===============================================================================
14.18.4
Fixed bug in fractional part for floating point with leading zeros after the decimal point.
===============================================================================
14.18.3
Unified 'to string' API.

View File

@ -259,6 +259,18 @@ namespace
{
etl::string<20> str;
CHECK_EQUAL(etl::string<20>(STR(" 0.000000")), etl::to_string(0.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::string<20>(STR("0.000000 ")), etl::to_string(0.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::string<20>(STR(" 0.000001")), etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::string<20>(STR("0.000001 ")), etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::string<20>(STR(" 1.000000")), etl::to_string(1.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::string<20>(STR("1.000000 ")), etl::to_string(1.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::string<20>(STR(" 1.000001")), etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::string<20>(STR("1.000001 ")), etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::string<20>(STR(" 12.345678")), etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::string<20>(STR("12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
}

View File

@ -253,6 +253,18 @@ namespace
{
etl::u16string<20> str;
CHECK_EQUAL(etl::u16string<20>(STR(" 0.000000")), etl::to_string(0.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u16string<20>(STR("0.000000 ")), etl::to_string(0.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::u16string<20>(STR(" 0.000001")), etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u16string<20>(STR("0.000001 ")), etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::u16string<20>(STR(" 1.000000")), etl::to_string(1.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u16string<20>(STR("1.000000 ")), etl::to_string(1.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::u16string<20>(STR(" 1.000001")), etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u16string<20>(STR("1.000001 ")), etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::u16string<20>(STR(" 12.345678")), etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u16string<20>(STR("12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
}

View File

@ -256,6 +256,18 @@ namespace
{
etl::u32string<20> str;
CHECK_EQUAL(etl::u32string<20>(STR(" 0.000000")), etl::to_string(0.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u32string<20>(STR("0.000000 ")), etl::to_string(0.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::u32string<20>(STR(" 0.000001")), etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u32string<20>(STR("0.000001 ")), etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::u32string<20>(STR(" 1.000000")), etl::to_string(1.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u32string<20>(STR("1.000000 ")), etl::to_string(1.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::u32string<20>(STR(" 1.000001")), etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u32string<20>(STR("1.000001 ")), etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::u32string<20>(STR(" 12.345678")), etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::u32string<20>(STR("12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
}

View File

@ -257,6 +257,18 @@ namespace
{
etl::wstring<20> str;
CHECK_EQUAL(etl::wstring<20>(STR(" 0.000000")), etl::to_string(0.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("0.000000 ")), etl::to_string(0.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" 0.000001")), etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("0.000001 ")), etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" 1.000000")), etl::to_string(1.0, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("1.000000 ")), etl::to_string(1.0, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" 1.000001")), etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("1.000001 ")), etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
CHECK_EQUAL(etl::wstring<20>(STR(" 12.345678")), etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
CHECK_EQUAL(etl::wstring<20>(STR("12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
}