Fixed incorrect result for negative float to string

This commit is contained in:
John Wellbelove 2019-10-11 18:35:58 +01:00
parent 71efdd5439
commit e5325aa379
9 changed files with 45 additions and 4 deletions

View File

@ -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<int64_t>(f_integral);
int64_t fractional = static_cast<int64_t>(round((value - f_integral) * multiplier));
int64_t fractional = etl::absolute(static_cast<int64_t>(round((value - f_integral) * multiplier)));
etl::private_to_string::add_integral_fractional(integral, fractional, str, integral_format, fractional_format);
}

View File

@ -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)

View File

@ -1,6 +1,6 @@
{
"name": "Embedded Template Library",
"version": "14.35.0",
"version": "14.35.1",
"authors": {
"name": "John Wellbelove",
"email": "<john.wellbelove@etlcpp.com>"

View File

@ -1,5 +1,5 @@
name=Embedded Template Library
version=14.35.0
version=14.35.1
author= John Wellbelove <john.wellbelove@etlcpp.com>
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
license=MIT

View File

@ -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.

View File

@ -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));
}
//*************************************************************************

View File

@ -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));
}
//*************************************************************************

View File

@ -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));
}
//*************************************************************************

View File

@ -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));
}
//*************************************************************************