mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Fixed incorrect result for negative float to string
This commit is contained in:
parent
71efdd5439
commit
e5325aa379
@ -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);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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>"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user