diff --git a/include/etl/private/to_string_helper.h b/include/etl/private/to_string_helper.h index db69b65a..456c7359 100644 --- a/include/etl/private/to_string_helper.h +++ b/include/etl/private/to_string_helper.h @@ -41,6 +41,7 @@ SOFTWARE. #include "../basic_format_spec.h" #include "../type_traits.h" #include "../container.h" +#include "../absolute.h" #include "../stl/algorithm.h" #include "../stl/iterator.h" @@ -258,7 +259,7 @@ namespace etl T f_integral = (value < T(0.0) ? ceil(value) : floor(value)); int64_t integral = static_cast(f_integral); - int64_t fractional = static_cast(round((value - f_integral) * multiplier)); + int64_t fractional = etl::absolute(static_cast(round((value - f_integral) * multiplier))); etl::private_to_string::add_integral_fractional(integral, fractional, str, integral_format, fractional_format); } diff --git a/include/etl/version.h b/include/etl/version.h index 58d4ef68..ea226332 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 14 #define ETL_VERSION_MINOR 35 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_PATCH 1 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 65c3e4b4..fcd7ecd6 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "14.35.0", + "version": "14.35.1", "authors": { "name": "John Wellbelove", "email": "" diff --git a/library.properties b/library.properties index 08ec01f7..756fc899 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=14.35.0 +version=14.35.1 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index c992de32..62ffba6d 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.35.1 +Fixed incorrect result for negative float to string. + =============================================================================== 14.35.0 Changed namespace for alternate ETL's STL support. diff --git a/test/test_to_string.cpp b/test/test_to_string.cpp index 79a73e2c..82152601 100644 --- a/test/test_to_string.cpp +++ b/test/test_to_string.cpp @@ -273,6 +273,9 @@ namespace 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())); + + CHECK_EQUAL(etl::string<20>(STR(" -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right())); + CHECK_EQUAL(etl::string<20>(STR("-12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left())); } //************************************************************************* @@ -285,6 +288,12 @@ namespace str.assign(STR("Result ")); CHECK_EQUAL(etl::string<20>(STR("Result 12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::string<20>(STR("Result -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::string<20>(STR("Result -12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true)); } //************************************************************************* diff --git a/test/test_to_u16string.cpp b/test/test_to_u16string.cpp index f1aea7da..8fd7d5b1 100644 --- a/test/test_to_u16string.cpp +++ b/test/test_to_u16string.cpp @@ -267,6 +267,9 @@ namespace 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())); + + CHECK_EQUAL(etl::u16string<20>(STR(" -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right())); + CHECK_EQUAL(etl::u16string<20>(STR("-12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left())); } //************************************************************************* @@ -279,6 +282,12 @@ namespace str.assign(STR("Result ")); CHECK_EQUAL(etl::u16string<20>(STR("Result 12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u16string<20>(STR("Result -12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true)); } //************************************************************************* diff --git a/test/test_to_u32string.cpp b/test/test_to_u32string.cpp index 4064dde8..7b5cc3ec 100644 --- a/test/test_to_u32string.cpp +++ b/test/test_to_u32string.cpp @@ -270,6 +270,9 @@ namespace 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())); + + CHECK_EQUAL(etl::u32string<20>(STR(" -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right())); + CHECK_EQUAL(etl::u32string<20>(STR("-12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left())); } //************************************************************************* @@ -282,6 +285,12 @@ namespace str.assign(STR("Result ")); CHECK_EQUAL(etl::u32string<20>(STR("Result 12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::u32string<20>(STR("Result -12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true)); } //************************************************************************* diff --git a/test/test_to_wstring.cpp b/test/test_to_wstring.cpp index bc575ce1..e5d3095c 100644 --- a/test/test_to_wstring.cpp +++ b/test/test_to_wstring.cpp @@ -271,6 +271,9 @@ namespace 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())); + + CHECK_EQUAL(etl::wstring<20>(STR(" -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right())); + CHECK_EQUAL(etl::wstring<20>(STR("-12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left())); } //************************************************************************* @@ -283,6 +286,12 @@ namespace str.assign(STR("Result ")); CHECK_EQUAL(etl::wstring<20>(STR("Result 12.345678 ")), etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result -12.345678")), etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true)); + + str.assign(STR("Result ")); + CHECK_EQUAL(etl::wstring<20>(STR("Result -12.345678 ")), etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true)); } //*************************************************************************