From c52d21054e451f890b68f3524b48f329a3e4689a Mon Sep 17 00:00:00 2001 From: Benedek Kupper <57992871+bku-sue@users.noreply.github.com> Date: Thu, 26 Aug 2021 10:47:11 +0200 Subject: [PATCH 1/7] to_string_helper: add string conversion helper for denominated integers (#408) With default format it will only print the meaningful fractional digits. If the format specifies the precision, it will print at least that many fractional digits. Signed-off-by: Benedek Kupper --- include/etl/private/to_string_helper.h | 67 ++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/include/etl/private/to_string_helper.h b/include/etl/private/to_string_helper.h index 255053d5..189a92ab 100644 --- a/include/etl/private/to_string_helper.h +++ b/include/etl/private/to_string_helper.h @@ -319,6 +319,73 @@ namespace etl etl::private_to_string::add_alignment(str, start, format); } + //*************************************************************************** + /// Helper function for divided integers. + //*************************************************************************** + template + void add_integral_denominated(T value, + typename etl::make_unsigned::type denominator, + TIString& str, + const etl::basic_format_spec& format, + bool append = false) + { + typedef typename TIString::iterator iterator; + typedef typename TIString::value_type type; + + if (!append) + { + str.clear(); + } + + iterator start = str.end(); + + { + // split to integral and fractional parts using the denominator + T integral = value / static_cast(denominator); + T fractional = absolute(value) % denominator; + + // find the number of useful (non-0) digits + size_t digits = 0; + for (auto div = denominator; div >= 10; div /= 10) + { + // this resolution doesn't yield meaningful digits, abort here + if ((fractional % div) == 0) + { + fractional /= div; + break; + } + digits++; + } + + etl::basic_format_spec integral_format = format; + integral_format.decimal().width(0); + etl::private_to_string::add_integral(integral, str, integral_format, true, etl::is_negative(integral)); + + // consider user-supplied minimum resolution + digits = max(digits, size_t(format.get_precision())); + if (digits) + { + str.push_back(type('.')); + etl::basic_format_spec fractional_format = integral_format; + fractional_format.width(digits).fill(type('0')).right(); + etl::private_to_string::add_integral(fractional, str, fractional_format, true, false); + } + } + + etl::private_to_string::add_alignment(str, start, format); + } + + template + void add_integral_denominated(T value, + typename etl::make_unsigned::type denominator, + TIString& str, + bool append = false) + { + etl::basic_format_spec format; + + etl::private_to_string::add_integral_denominated(value, denominator, str, format, append); + } + //*************************************************************************** /// Helper function for pointers. //*************************************************************************** From adda3bb1dc1801070e76930b8971246023f90719 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 27 Aug 2021 18:42:46 +0100 Subject: [PATCH 2/7] Fixed incomplete template specialisations in type_traits.h --- .gitignore | 1 + .../etl/generators/type_traits_generator.h | 66 +++++---------- include/etl/type_traits.h | 66 +++++---------- test/runtests.sh | 80 +++++++++++++++---- test/test_delegate.cpp | 17 ++++ 5 files changed, 118 insertions(+), 112 deletions(-) diff --git a/.gitignore b/.gitignore index 4c9515dd..72c021e0 100644 --- a/.gitignore +++ b/.gitignore @@ -324,3 +324,4 @@ test/vs2019/Test1 test/vs2019/Test2 test/vs2019/Debug MSVC - Force C++03 test/vs2019/Debug LLVM - No STL +test/vs2019/Debug - No STL diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 4716f9ed..9f734c44 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -284,8 +284,8 @@ namespace etl //*************************************************************************** /// is_signed template struct is_signed : false_type {}; - template <> struct is_signed : integral_constant {}; - template <> struct is_signed : public etl::integral_constant(wchar_t(-1) < wchar_t(0))> {}; + template <> struct is_signed : etl::bool_constant<(char(255) < 0)> {}; + template <> struct is_signed : public etl::bool_constant(wchar_t(-1) < wchar_t(0))> {}; template <> struct is_signed : true_type {}; template <> struct is_signed : true_type {}; template <> struct is_signed : true_type {}; @@ -307,9 +307,9 @@ namespace etl /// is_unsigned template struct is_unsigned : false_type {}; template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : integral_constant 0)> {}; + template <> struct is_unsigned : etl::bool_constant<(char(255) > 0)> {}; template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : public etl::integral_constant wchar_t(0))> {}; + template <> struct is_unsigned : public etl::bool_constant<(wchar_t(-1) > wchar_t(0))> {}; template <> struct is_unsigned : true_type {}; template <> struct is_unsigned : true_type {}; template <> struct is_unsigned : true_type {}; @@ -360,7 +360,7 @@ namespace etl //*************************************************************************** /// is_arithmetic - template struct is_arithmetic : integral_constant::value || is_floating_point::value> {}; + template struct is_arithmetic : etl::bool_constant::value || is_floating_point::value> {}; #if ETL_CPP17_SUPPORTED template @@ -369,7 +369,7 @@ namespace etl //*************************************************************************** /// is_fundamental - template struct is_fundamental : integral_constant::value || is_void::value> {}; + template struct is_fundamental : etl::bool_constant::value || is_void::value> {}; #if ETL_CPP17_SUPPORTED template @@ -378,7 +378,7 @@ namespace etl //*************************************************************************** /// is_compound - template struct is_compound : integral_constant::value> {}; + template struct is_compound : etl::bool_constant::value> {}; #if ETL_CPP17_SUPPORTED template @@ -445,7 +445,7 @@ namespace etl //*************************************************************************** /// is_pod /// Only fundamental and pointers types are recognised. - template struct is_pod : etl::integral_constant::value || etl::is_pointer::value> {}; + template struct is_pod : etl::bool_constant::value || etl::is_pointer::value> {}; #if ETL_CPP17_SUPPORTED template @@ -644,7 +644,7 @@ namespace etl } template - struct is_class : etl::integral_constant(0)) == 1U> {}; + struct is_class : etl::bool_constant(0)) == 1U> {}; #if ETL_CPP17_SUPPORTED template @@ -711,12 +711,12 @@ namespace etl #if defined(ETL_COMPILER_ARM5) template - struct is_convertible : etl::integral_constant {}; + struct is_convertible : etl::bool_constant<__is_convertible_to(TFrom, TTo)> {}; #else template - struct is_convertible : etl::integral_constant(0))::value && - decltype(private_type_traits::nonvoid_convertible(0))::value) || - (etl::is_void::value && etl::is_void::value)> {}; + struct is_convertible : etl::bool_constant<(decltype(private_type_traits::returnable(0))::value && + decltype(private_type_traits::nonvoid_convertible(0))::value) || + (etl::is_void::value && etl::is_void::value)> {}; #endif #endif @@ -1554,16 +1554,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_constructible; - template - struct is_trivially_constructible : public etl::true_type + struct is_trivially_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_constructible; #endif //********************************************* @@ -1574,16 +1568,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_copy_constructible; - template - struct is_trivially_copy_constructible : public etl::true_type + struct is_trivially_copy_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_copy_constructible; #endif //********************************************* @@ -1594,16 +1582,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_destructible; - template - struct is_trivially_destructible : public etl::true_type + struct is_trivially_destructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_destructible; #endif //********************************************* @@ -1614,16 +1596,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_copy_assignable; - template - struct is_trivially_copy_assignable : public etl::true_type + struct is_trivially_copy_assignable : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_copy_assignable; #endif //********************************************* @@ -1634,16 +1610,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_copyable; - template - struct is_trivially_copyable : public etl::true_type + struct is_trivially_copyable : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_copyable; #endif #elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 5ec0db6f..a96a9baf 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -272,8 +272,8 @@ namespace etl //*************************************************************************** /// is_signed template struct is_signed : false_type {}; - template <> struct is_signed : integral_constant {}; - template <> struct is_signed : public etl::integral_constant(wchar_t(-1) < wchar_t(0))> {}; + template <> struct is_signed : etl::bool_constant<(char(255) < 0)> {}; + template <> struct is_signed : public etl::bool_constant(wchar_t(-1) < wchar_t(0))> {}; template <> struct is_signed : true_type {}; template <> struct is_signed : true_type {}; template <> struct is_signed : true_type {}; @@ -295,9 +295,9 @@ namespace etl /// is_unsigned template struct is_unsigned : false_type {}; template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : integral_constant 0)> {}; + template <> struct is_unsigned : etl::bool_constant<(char(255) > 0)> {}; template <> struct is_unsigned : true_type {}; - template <> struct is_unsigned : public etl::integral_constant wchar_t(0))> {}; + template <> struct is_unsigned : public etl::bool_constant<(wchar_t(-1) > wchar_t(0))> {}; template <> struct is_unsigned : true_type {}; template <> struct is_unsigned : true_type {}; template <> struct is_unsigned : true_type {}; @@ -348,7 +348,7 @@ namespace etl //*************************************************************************** /// is_arithmetic - template struct is_arithmetic : integral_constant::value || is_floating_point::value> {}; + template struct is_arithmetic : etl::bool_constant::value || is_floating_point::value> {}; #if ETL_CPP17_SUPPORTED template @@ -357,7 +357,7 @@ namespace etl //*************************************************************************** /// is_fundamental - template struct is_fundamental : integral_constant::value || is_void::value> {}; + template struct is_fundamental : etl::bool_constant::value || is_void::value> {}; #if ETL_CPP17_SUPPORTED template @@ -366,7 +366,7 @@ namespace etl //*************************************************************************** /// is_compound - template struct is_compound : integral_constant::value> {}; + template struct is_compound : etl::bool_constant::value> {}; #if ETL_CPP17_SUPPORTED template @@ -433,7 +433,7 @@ namespace etl //*************************************************************************** /// is_pod /// Only fundamental and pointers types are recognised. - template struct is_pod : etl::integral_constant::value || etl::is_pointer::value> {}; + template struct is_pod : etl::bool_constant::value || etl::is_pointer::value> {}; #if ETL_CPP17_SUPPORTED template @@ -632,7 +632,7 @@ namespace etl } template - struct is_class : etl::integral_constant(0)) == 1U> {}; + struct is_class : etl::bool_constant(0)) == 1U> {}; #if ETL_CPP17_SUPPORTED template @@ -699,12 +699,12 @@ namespace etl #if defined(ETL_COMPILER_ARM5) template - struct is_convertible : etl::integral_constant {}; + struct is_convertible : etl::bool_constant<__is_convertible_to(TFrom, TTo)> {}; #else template - struct is_convertible : etl::integral_constant(0))::value && - decltype(private_type_traits::nonvoid_convertible(0))::value) || - (etl::is_void::value && etl::is_void::value)> {}; + struct is_convertible : etl::bool_constant<(decltype(private_type_traits::returnable(0))::value && + decltype(private_type_traits::nonvoid_convertible(0))::value) || + (etl::is_void::value && etl::is_void::value)> {}; #endif #endif @@ -1547,16 +1547,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_constructible; - template - struct is_trivially_constructible : public etl::true_type + struct is_trivially_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_constructible; #endif //********************************************* @@ -1567,16 +1561,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_copy_constructible; - template - struct is_trivially_copy_constructible : public etl::true_type + struct is_trivially_copy_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_copy_constructible; #endif //********************************************* @@ -1587,16 +1575,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_destructible; - template - struct is_trivially_destructible : public etl::true_type + struct is_trivially_destructible : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_destructible; #endif //********************************************* @@ -1607,16 +1589,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_copy_assignable; - template - struct is_trivially_copy_assignable : public etl::true_type + struct is_trivially_copy_assignable : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_copy_assignable; #endif //********************************************* @@ -1627,16 +1603,10 @@ namespace etl { }; #else - template ::value || etl::is_pointer::value> - struct is_trivially_copyable; - template - struct is_trivially_copyable : public etl::true_type + struct is_trivially_copyable : public etl::bool_constant::value || etl::is_pointer::value> { }; - - template - struct is_trivially_copyable; #endif #elif defined(ETL_USE_TYPE_TRAITS_BUILTINS) && !defined(ETL_USER_DEFINED_TYPE_TRAITS) diff --git a/test/runtests.sh b/test/runtests.sh index d6bc72ba..30d63840 100755 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -15,12 +15,18 @@ gcc --version | grep gcc | tee -a log.txt CC=gcc CXX=g++ cmake --cmake-clean-cache -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF .. make -j8 if [ $? -eq 0 ]; then - echo "Passed" + echo "<<<< Passed >>>>" +else + echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + echo "<<<< Passed >>>>" else echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt exit $? fi -./etl_tests | tee log.txt echo "" echo "-----------------------------------------------" | tee -a log.txt echo " GCC - STL - Force C++03" | tee -a log.txt @@ -29,12 +35,18 @@ gcc --version | grep gcc | tee -a log.txt CC=gcc CXX=g++ cmake --cmake-clean-cache -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=ON .. make -j8 if [ $? -eq 0 ]; then - echo "Passed" + echo "<<<< Passed >>>>" +else + echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + echo "<<<< Passed >>>>" else echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt exit $? fi -./etl_tests | tee log.txt echo "" echo "-----------------------------------------------" | tee -a log.txt echo " GCC - No STL" | tee -a log.txt @@ -43,12 +55,18 @@ gcc --version | grep gcc | tee -a log.txt CC=gcc CXX=g++ cmake --cmake-clean-cache -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF .. make -j8 if [ $? -eq 0 ]; then - echo "Passed" + echo "<<<< Passed >>>>" +else + echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + echo "<<<< Passed >>>>" else echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt exit $? fi -./etl_tests | tee log.txt echo "" echo "-----------------------------------------------" | tee -a log.txt echo " GCC - No STL - Builtins" | tee -a log.txt @@ -57,12 +75,18 @@ gcc --version | grep gcc | tee -a log.txt CC=gcc CXX=g++ cmake --cmake-clean-cache -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF .. make -j8 if [ $? -eq 0 ]; then - echo "Passed" + echo "<<<< Passed >>>>" +else + echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + echo "<<<< Passed >>>>" else echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt exit $? fi -./etl_tests | tee log.txt #****************************************************************************** # CLANG @@ -75,12 +99,18 @@ clang --version | grep clang | tee -a log.txt CC=clang CXX=clang++ cmake --cmake-clean-cache -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF .. make -j8 if [ $? -eq 0 ]; then - echo "Passed" + echo "<<<< Passed >>>>" +else + echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + echo "<<<< Passed >>>>" else echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt exit $? fi -./etl_tests | tee log.txt echo "" echo "-----------------------------------------------" | tee -a log.txt echo " Clang - STL - Force C++03" | tee -a log.txt @@ -89,12 +119,18 @@ clang --version | grep clang | tee -a log.txt CC=clang CXX=clang++ cmake --cmake-clean-cache -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=ON .. make -j8 if [ $? -eq 0 ]; then - echo "Passed" + echo "<<<< Passed >>>>" +else + echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + echo "<<<< Passed >>>>" else echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt exit $? fi -./etl_tests | tee log.txt echo "" echo "-----------------------------------------------" | tee -a log.txt echo " Clang - No STL" | tee -a log.txt @@ -103,12 +139,18 @@ clang --version | grep clang | tee -a log.txt CC=clang CXX=clang++ cmake --cmake-clean-cache -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF .. make -j8 if [ $? -eq 0 ]; then - echo "Passed" + echo "<<<< Passed >>>>" +else + echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + echo "<<<< Passed >>>>" else echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt exit $? fi -./etl_tests | tee log.txt echo "" echo "-----------------------------------------------" | tee -a log.txt echo " Clang - No STL - Builtins" | tee -a log.txt @@ -117,12 +159,18 @@ clang --version | grep clang | tee -a log.txt CC=clang CXX=clang++ cmake --cmake-clean-cache -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF .. make -j8 if [ $? -eq 0 ]; then - echo "Passed" + echo "<<<< Passed >>>>" +else + echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt + exit $? +fi +./etl_tests +if [ $? -eq 0 ]; then + echo "<<<< Passed >>>>" else echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt exit $? fi -./etl_tests | tee log.txt echo "" echo "-----------------------------------------------" | tee -a log.txt echo " Tests Completed" | tee -a log.txt diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index 9d2858ba..8d719916 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -29,6 +29,7 @@ SOFTWARE. #include "unit_test_framework.h" #include "etl/delegate.h" +#include "etl/vector.h" namespace { @@ -171,6 +172,12 @@ namespace } }; + //******************************************* + int times_2(int a) + { + return a * 2; + } + Test test_static; const Test const_test_static; } @@ -877,5 +884,15 @@ namespace CHECK(d1 != d2); } + + //************************************************************************* + TEST(test_issue_418) + { + etl::vector, 5> vector_of_delegates; + + vector_of_delegates.push_back(etl::delegate::create()); + + CHECK_EQUAL(42, vector_of_delegates.front()(21)); + } }; } From 20f0599f84a723432001bb98fa12fa74a2a88871 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 27 Aug 2021 19:24:15 +0100 Subject: [PATCH 3/7] Added missing #include for variant. Updated version numbers --- include/etl/variant.h | 2 ++ include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- meson.build | 2 +- support/Release notes.txt | 3 +++ 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/etl/variant.h b/include/etl/variant.h index c8664590..cfd27e9f 100644 --- a/include/etl/variant.h +++ b/include/etl/variant.h @@ -31,6 +31,8 @@ SOFTWARE. #ifndef ETL_VARIANT_INCLUDED #define ETL_VARIANT_INCLUDED +#include "platform.h" + #if !ETL_CPP11_SUPPORTED || ETL_USE_LEGACY_VARIANT #include "private/variant_legacy.h" #else diff --git a/include/etl/version.h b/include/etl/version.h index d694487e..4fbd4ed3 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 20 #define ETL_VERSION_MINOR 16 -#define ETL_VERSION_PATCH 1 +#define ETL_VERSION_PATCH 2 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 2375b99b..c067cc0a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ETL Embedded Template Library", - "version": "20.16.1", + "version": "20.16.2", "author s": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 7e10a585..473dcc72 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library ETL -version=20.16.1 +version=20.16.2 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/meson.build b/meson.build index 89b9af6a..b0554ef6 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,7 @@ project('PROJECT_NAME', 'cpp_std=c++17', 'build.cpp_std=c++17', ], meson_version: '>=0.54.0', - version: '20.16.1' + version: '20.16.2' ) ###################### diff --git a/support/Release notes.txt b/support/Release notes.txt index 6898696e..c37cee44 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,6 @@ +=============================================================================== +20.16.2 Fixed incomplete template specialisations in type_traits.h for C++11 + =============================================================================== 20.16.1 Fix for etl::mutex::try_lock() for GCC From 3659d6f3d965076fdaa28242d711b93b869fb05c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 27 Aug 2021 14:33:03 +0100 Subject: [PATCH 4/7] Working code --- include/etl/private/to_string_helper.h | 342 +++++++++++-------------- include/etl/to_string.h | 24 ++ include/etl/to_u16string.h | 25 ++ include/etl/to_u32string.h | 24 ++ include/etl/to_wstring.h | 24 ++ test/test_to_string.cpp | 104 ++++++++ test/test_to_u16string.cpp | 36 +++ test/test_to_u32string.cpp | 36 +++ test/test_to_wstring.cpp | 36 +++ 9 files changed, 464 insertions(+), 187 deletions(-) diff --git a/include/etl/private/to_string_helper.h b/include/etl/private/to_string_helper.h index 189a92ab..f5cf637b 100644 --- a/include/etl/private/to_string_helper.h +++ b/include/etl/private/to_string_helper.h @@ -301,7 +301,7 @@ namespace etl // Find the integral part of the floating point T f_integral = (value < T(0.0) ? ceil(value) : floor(value)); - workspace_t integral = static_cast(f_integral); + workspace_t integral = etl::absolute(static_cast(f_integral)); // Find the fractional part of the floating point. workspace_t fractional = etl::absolute(static_cast(round((value - f_integral) * multiplier))); @@ -324,7 +324,7 @@ namespace etl //*************************************************************************** template void add_integral_denominated(T value, - typename etl::make_unsigned::type denominator, + workspace_t denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) @@ -339,53 +339,73 @@ namespace etl iterator start = str.end(); + // Split to integral and fractional parts using the denominator + workspace_t integral = absolute(value) / denominator; + workspace_t fractional = absolute(value) % denominator; + + uint32_t denominator_digits = 0U; + uint32_t multiplier = 1U; + + while (multiplier < fractional) { - // split to integral and fractional parts using the denominator - T integral = value / static_cast(denominator); - T fractional = absolute(value) % denominator; + multiplier *= 10U; + ++denominator_digits; + } - // find the number of useful (non-0) digits - size_t digits = 0; - for (auto div = denominator; div >= 10; div /= 10) + etl::basic_format_spec integral_format = format; + integral_format.decimal().width(0U).precision(format.get_precision() > denominator_digits ? denominator_digits : format.get_precision()); + + etl::basic_format_spec fractional_format = integral_format; + fractional_format.width(integral_format.get_precision()).fill(type('0')).left(); + + if (fractional != 0U) + { + // Adjust the fractional with rounding. + uint32_t fractional_digits = 0U; + uint32_t multiplier = 1U; + + while (multiplier < fractional) { - // this resolution doesn't yield meaningful digits, abort here - if ((fractional % div) == 0) + multiplier *= 10U; + ++fractional_digits; + } + + // Do we need to round? + if (fractional_digits > fractional_format.get_width()) + { + uint32_t count = fractional_digits - fractional_format.get_width(); + + while (count > 0U) { - fractional /= div; - break; + // Check the last digit. + if (count == 1U) + { + // Round up? + if ((fractional % 10U) >= 5U) + { + fractional += 10U; + } + } + + fractional /= 10U; + multiplier /= 10U; + + --count; } - digits++; - } + } - etl::basic_format_spec integral_format = format; - integral_format.decimal().width(0); - etl::private_to_string::add_integral(integral, str, integral_format, true, etl::is_negative(integral)); - - // consider user-supplied minimum resolution - digits = max(digits, size_t(format.get_precision())); - if (digits) + // Check for a rounding carry to the integral. + if (fractional == multiplier) { - str.push_back(type('.')); - etl::basic_format_spec fractional_format = integral_format; - fractional_format.width(digits).fill(type('0')).right(); - etl::private_to_string::add_integral(fractional, str, fractional_format, true, false); + ++integral; + fractional = 0U; } } + etl::private_to_string::add_integral_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value)); etl::private_to_string::add_alignment(str, start, format); } - template - void add_integral_denominated(T value, - typename etl::make_unsigned::type denominator, - TIString& str, - bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_integral_denominated(value, denominator, str, format, append); - } - //*************************************************************************** /// Helper function for pointers. //*************************************************************************** @@ -445,22 +465,7 @@ namespace etl //********************************************************************************************************* //*************************************************************************** - /// For booleans. Default format spec. - //*************************************************************************** - template - const TIString& to_string(const bool value, - TIString& str, - bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_boolean(value, str, format, append); - - return str; - } - - //*************************************************************************** - /// For booleans. Supplied format spec. + /// For booleans. //*************************************************************************** template const TIString& to_string(const bool value, @@ -474,22 +479,7 @@ namespace etl } //*************************************************************************** - /// For pointers. Default format spec. - //*************************************************************************** - template - const TIString& to_string(const volatile void* value, - TIString& str, - bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_pointer(value, str, format, append); - - return str; - } - - //*************************************************************************** - /// For pointers. Supplied format spec. + /// For pointers. //*************************************************************************** template const TIString& to_string(const volatile void* value, @@ -503,24 +493,9 @@ namespace etl } #if ETL_NOT_USING_64BIT_TYPES - //*************************************************************************** - /// For signed integrals less than 64 bits. Default format spec. - //*************************************************************************** - template - typename etl::enable_if::value && - etl::is_signed::value && - !etl::is_same::value>::value, const TIString& > ::type - to_string(const T value, TIString& str, bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_integral(int32_t(value), str, format, append, etl::is_negative(value)); - - return str; - } //*************************************************************************** - /// For signed integrals less than 64 bits. Supplied format spec. + /// For signed integrals less than 64 bits. //*************************************************************************** template typename etl::enable_if::value && @@ -534,23 +509,7 @@ namespace etl } //*************************************************************************** - /// For unsigned integrals less than 64 bits. Default format spec. - //*************************************************************************** - template - typename etl::enable_if::value && - etl::is_unsigned::value && - !etl::is_same::value>::value, const TIString& > ::type - to_string(const T value, TIString& str, bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_integral(uint32_t(value), str, format, append, false); - - return str; - } - - //*************************************************************************** - /// For unsigned integrals less than 64 bits. Supplied format spec. + /// For unsigned integrals less than 64 bits. //*************************************************************************** template typename etl::enable_if::value && @@ -562,26 +521,39 @@ namespace etl return str; } + + //*************************************************************************** + /// For signed integrals less than 64 bits. + //*************************************************************************** + template + typename etl::enable_if::value&& + etl::is_signed::value && + !etl::is_same::value>::value, const TIString& > ::type + to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) + { + etl::private_to_string::add_integral_denominated(int32_t(value), denominator, str, format, append, etl::is_negative(value)); + + return str; + } + + //*************************************************************************** + /// For unsigned integrals less than 64 bits. + //*************************************************************************** + template + typename etl::enable_if::value&& + etl::is_unsigned::value && + !etl::is_same::value>::value, const TIString& > ::type + to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) + { + etl::private_to_string::add_integral_denominated(uint32_t(value), denominator, str, format, append, false); + + return str; + } + #else - //*************************************************************************** - /// For signed integrals less than 64 bits. Default format spec. - //*************************************************************************** - template - typename etl::enable_if::value && - etl::is_signed::value && - !etl::is_same::value && - !etl::is_same::value, const TIString&>::type - to_string(const T value, TIString& str, bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_integral(int32_t(value), str, format, append, etl::is_negative(value)); - - return str; - } //*************************************************************************** - /// For signed integrals less than 64 bits. Supplied format spec. + /// For signed integrals less than 64 bits. //*************************************************************************** template typename etl::enable_if::value && @@ -596,24 +568,7 @@ namespace etl } //*************************************************************************** - /// For unsigned integrals less than 64 bits. Default format spec. - //*************************************************************************** - template - typename etl::enable_if::value && - etl::is_unsigned::value && - !etl::is_same::value && - !etl::is_same::value, const TIString&>::type - to_string(const T value, TIString& str, bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_integral(uint32_t(value), str, format, append, false); - - return str; - } - - //*************************************************************************** - /// For unsigned integrals less than 64 bits. Supplied format spec. + /// For unsigned integrals less than 64 bits. //*************************************************************************** template typename etl::enable_if::value && @@ -628,24 +583,7 @@ namespace etl } //*************************************************************************** - /// For signed 64 bit integrals. Default format spec. - //*************************************************************************** - template - typename etl::enable_if::value && - etl::is_signed::value && - !etl::is_same::value && - etl::is_same::value, const TIString&>::type - to_string(const T value, TIString& str, bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_integral(int64_t(value), str, format, append, etl::is_negative(value)); - - return str; - } - - //*************************************************************************** - /// For signed 64 bit integrals. Supplied format spec. + /// For signed 64 bit integrals. //*************************************************************************** template typename etl::enable_if::value && @@ -660,24 +598,7 @@ namespace etl } //*************************************************************************** - /// For unsigned 64 bit integrals. Default format spec. - //*************************************************************************** - template - typename etl::enable_if::value && - etl::is_unsigned::value && - !etl::is_same::value && - etl::is_same::value, const TIString&>::type - to_string(const T value, TIString& str, bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_integral(uint64_t(value), str, format, append, false); - - return str; - } - - //*************************************************************************** - /// For unsigned 64 bit integrals. Supplied format spec. + /// For unsigned 64 bit integrals. //*************************************************************************** template typename etl::enable_if::value && @@ -690,24 +611,71 @@ namespace etl return str; } + + //*************************************************************************** + /// For signed integrals less than 64 bits. + //*************************************************************************** + template + typename etl::enable_if::value&& + etl::is_signed::value && + !etl::is_same::value && + !etl::is_same::value, const TIString&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) + { + etl::private_to_string::add_integral_denominated(int32_t(value), denominator, str, format, append); + + return str; + } + + //*************************************************************************** + /// For unsigned integrals less than 64 bits. + //*************************************************************************** + template + typename etl::enable_if::value&& + etl::is_unsigned::value && + !etl::is_same::value && + !etl::is_same::value, const TIString&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) + { + etl::private_to_string::add_integral_denominated(uint32_t(value), denominator, str, format, append); + + return str; + } + + //*************************************************************************** + /// For signed 64 bit integrals. + //*************************************************************************** + template + typename etl::enable_if::value&& + etl::is_signed::value && + !etl::is_same::value&& + etl::is_same::value, const TIString&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) + { + etl::private_to_string::add_integral_denominated(int64_t(value), denominator, str, format, append, etl::is_negative(value)); + + return str; + } + + //*************************************************************************** + /// For unsigned 64 bit integrals. + //*************************************************************************** + template + typename etl::enable_if::value&& + etl::is_unsigned::value && + !etl::is_same::value&& + etl::is_same::value, const TIString&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) + { + etl::private_to_string::add_integral(uint64_t(value), denominator, str, format, append, false); + + return str; + } + #endif //*************************************************************************** - /// For floating point. Default format spec. - //*************************************************************************** - template - typename etl::enable_if::value, const TIString&>::type - to_string(const T value, TIString& str, bool append = false) - { - etl::basic_format_spec format; - - etl::private_to_string::add_floating_point(value, str, format, append); - - return str; - } - - //*************************************************************************** - /// For floating point. Supplied format spec. + /// For floating point. //*************************************************************************** template typename etl::enable_if::value, const TIString&>::type diff --git a/include/etl/to_string.h b/include/etl/to_string.h index 4535d2c9..de09aec2 100644 --- a/include/etl/to_string.h +++ b/include/etl/to_string.h @@ -65,6 +65,30 @@ namespace etl return private_to_string::to_string(value, str, format, append); } + //*************************************************************************** + /// Default format spec. + /// !etl::istring && !etl::string_view + //*************************************************************************** + template + typename etl::enable_if::value && !etl::is_same::value, const etl::istring&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, etl::istring& str, bool append = false) + { + etl::format_spec format; + + return private_to_string::to_string(value, denominator, str, format, append); + } + + //*************************************************************************** + /// Supplied format spec. + /// !etl::istring && !etl::string_view + //*************************************************************************** + template + typename etl::enable_if::value && !etl::is_same::value, const etl::istring&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, etl::istring& str, const etl::format_spec& format, bool append = false) + { + return private_to_string::to_string(value, denominator, str, format, append); + } + //*************************************************************************** /// Default format spec. /// etl::istring diff --git a/include/etl/to_u16string.h b/include/etl/to_u16string.h index cfb6ffe8..9d117aa2 100644 --- a/include/etl/to_u16string.h +++ b/include/etl/to_u16string.h @@ -65,6 +65,31 @@ namespace etl return private_to_string::to_string(value, str, format, append); } + //*************************************************************************** + /// Default format spec. + /// !etl::iu16string && !etl::u16string_view + //*************************************************************************** + template + typename etl::enable_if::value && !etl::is_same::value, const etl::iu16string&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, etl::iu16string& str, bool append = false) + { + etl::u16format_spec format; + + return private_to_string::to_string(value, denominator, str, format, append); + } + + //*************************************************************************** + /// Supplied format spec. + /// !etl::u16string_view && !etl::u16string_view + //*************************************************************************** + template + typename etl::enable_if::value && !etl::is_same::value, const etl::iu16string&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, etl::iu16string& str, const etl::u16format_spec& format, bool append = false) + { + return private_to_string::to_string(value, denominator, str, format, append); + } + + //*************************************************************************** /// Default format spec. /// etl::iu16string diff --git a/include/etl/to_u32string.h b/include/etl/to_u32string.h index f07451cd..a17e6ba8 100644 --- a/include/etl/to_u32string.h +++ b/include/etl/to_u32string.h @@ -65,6 +65,30 @@ namespace etl return private_to_string::to_string(value, str, format, append); } + //*************************************************************************** + /// Default format spec. + /// !etl::iu32string && !etl::u16string_view + //*************************************************************************** + template + typename etl::enable_if::value && !etl::is_same::value, const etl::iu32string&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, etl::iu32string& str, bool append = false) + { + etl::u32format_spec format; + + return private_to_string::to_string(value, denominator, str, format, append); + } + + //*************************************************************************** + /// Supplied format spec. + /// !etl::u16string_view && !etl::u16string_view + //*************************************************************************** + template + typename etl::enable_if::value && !etl::is_same::value, const etl::iu32string&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, etl::iu32string& str, const etl::u32format_spec& format, bool append = false) + { + return private_to_string::to_string(value, denominator, str, format, append); + } + //*************************************************************************** /// Default format spec. /// etl::iu32string diff --git a/include/etl/to_wstring.h b/include/etl/to_wstring.h index 1612d02e..7f710674 100644 --- a/include/etl/to_wstring.h +++ b/include/etl/to_wstring.h @@ -65,6 +65,30 @@ namespace etl return private_to_string::to_string(value, str, format, append); } + //*************************************************************************** + /// Default format spec. + /// !etl::iu32string && !etl::u16string_view + //*************************************************************************** + template + typename etl::enable_if::value && !etl::is_same::value, const etl::iwstring&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, etl::iwstring& str, bool append = false) + { + etl::wformat_spec format; + + return private_to_string::to_string(value, denominator, str, format, append); + } + + //*************************************************************************** + /// Supplied format spec. + /// !etl::u16string_view && !etl::u16string_view + //*************************************************************************** + template + typename etl::enable_if::value && !etl::is_same::value, const etl::iwstring&>::type + to_string(const T value, typename etl::make_unsigned::type denominator, etl::iwstring& str, const etl::wformat_spec& format, bool append = false) + { + return private_to_string::to_string(value, denominator, str, format, append); + } + //*************************************************************************** /// Default format spec. /// etl::iwstring diff --git a/test/test_to_string.cpp b/test/test_to_string.cpp index 5221884f..9dc4bc9a 100644 --- a/test/test_to_string.cpp +++ b/test/test_to_string.cpp @@ -278,6 +278,14 @@ namespace CHECK(etl::string<20>(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right())); CHECK(etl::string<20>(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left())); + + // Positive rollover + CHECK(etl::string<20>(STR(" 2.000000")) == etl::to_string(1.9999996, str, Format().precision(6).width(10).right())); + CHECK(etl::string<20>(STR("2.000000 ")) == etl::to_string(1.9999996, str, Format().precision(6).width(10).left())); + + // Negative rollover + CHECK(etl::string<20>(STR(" -2.000000")) == etl::to_string(-1.9999996, str, Format().precision(6).width(10).right())); + CHECK(etl::string<20>(STR("-2.000000 ")) == etl::to_string(-1.9999996, str, Format().precision(6).width(10).left())); } //************************************************************************* @@ -425,6 +433,102 @@ namespace to_string(&cvi, str, Format().hex().width(10).left().fill(STR('0')), true); CHECK(compare == str); } + + //************************************************************************* + TEST(test_integer_denominator_default_format) + { + etl::string<20> result; + int value = -1234567; + + etl::to_string(value, 1000000, result); + + CHECK_EQUAL(etl::string<20>("-1").c_str(), result.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_huge_precision) + { + etl::string<20> result; + int value = -1234560; + + etl::format_spec format = Format().precision(100); + + etl::to_string(value, 1000000, result, format); + + CHECK_EQUAL(etl::string<20>("-1.234560").c_str(), result.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_shorter_width) + { + etl::string<20> result_i; + int value_i = -1234560; + + etl::string<20> result_d; + double value_d = -1.234560; + + etl::format_spec format = Format().precision(4).width(6).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("-1.2346")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_larger_width) + { + etl::string<20> result_i; + int value_i = -1234560; + + etl::string<20> result_d; + double value_d = -1.234560; + + etl::format_spec format = Format().precision(4).width(15).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR(" -1.2346")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_positive_rollover) + { + etl::string<20> result_i; + int value_i = 1999990; + + etl::string<20> result_d; + double value_d = 1.999990; + + etl::format_spec format = Format().precision(4).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("2.0000")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_negative_rollover) + { + etl::string<20> result_i; + int value_i = -1999990; + + etl::string<20> result_d; + double value_d = -1.999990; + + etl::format_spec format = Format().precision(4).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("-2.0000")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } }; } diff --git a/test/test_to_u16string.cpp b/test/test_to_u16string.cpp index fff948be..85b3af67 100644 --- a/test/test_to_u16string.cpp +++ b/test/test_to_u16string.cpp @@ -348,6 +348,42 @@ namespace str.assign(STR("Result ")); CHECK(etl::u16string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); } + + ////************************************************************************* + //TEST(test_integer_denominator_shorter_width) + //{ + // etl::u16string<20> result_i; + // int value_i = -1234567; + + // etl::u16string<20> result_d; + // double value_d = -2.9543; + + // etl::u16format_spec format = Format().precision(4).width(6).right(); + + // etl::to_string(value_i, 1000000, result_i, format); + // etl::to_string(value_d, result_d, format); + + // CHECK_EQUAL(etl::u16string<20>(STR("-1.2346")).c_str(), result_i.c_str()); + // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + //} + + ////************************************************************************* + //TEST(test_integer_denominator_larger_width) + //{ + // etl::u16string<20> result_i; + // int value_i = -1234567; + + // etl::u16string<20> result_d; + // double value_d = -2.9543; + + // etl::u16format_spec format = Format().precision(4).width(15).right(); + + // etl::to_string(value_i, 1000000, result_i, format); + // etl::to_string(value_d, result_d, format); + + // CHECK_EQUAL(etl::u16string<20>(STR(" -1.2345")).c_str(), result_i.c_str()); + // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + //} }; } diff --git a/test/test_to_u32string.cpp b/test/test_to_u32string.cpp index e5928416..07d9909e 100644 --- a/test/test_to_u32string.cpp +++ b/test/test_to_u32string.cpp @@ -353,6 +353,42 @@ namespace str.assign(STR("Result ")); CHECK(etl::u32string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); } + + ////************************************************************************* + //TEST(test_integer_denominator_shorter_width) + //{ + // etl::u32string<20> result_i; + // int value_i = -1234567; + + // etl::u32string<20> result_d; + // double value_d = -2.9543; + + // etl::u32format_spec format = Format().precision(4).width(6).right(); + + // etl::to_string(value_i, 1000000, result_i, format); + // etl::to_string(value_d, result_d, format); + + // CHECK_EQUAL(etl::u32string<20>(STR("-1.2345")).c_str(), result_i.c_str()); + // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + //} + + ////************************************************************************* + //TEST(test_integer_denominator_larger_width) + //{ + // etl::u32string<20> result_i; + // int value_i = -1234567; + + // etl::u32string<20> result_d; + // double value_d = -2.9543; + + // etl::u32format_spec format = Format().precision(4).width(15).right(); + + // etl::to_string(value_i, 1000000, result_i, format); + // etl::to_string(value_d, result_d, format); + + // CHECK_EQUAL(etl::u32string<20>(STR(" -1.2345")).c_str(), result_i.c_str()); + // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + //} }; } diff --git a/test/test_to_wstring.cpp b/test/test_to_wstring.cpp index d213ab80..f1cc0f81 100644 --- a/test/test_to_wstring.cpp +++ b/test/test_to_wstring.cpp @@ -415,6 +415,42 @@ namespace to_string(&cvi, str, Format().hex().width(10).left().fill(STR('0')), true); CHECK(compare == str); } + + ////************************************************************************* + //TEST(test_integer_denominator_shorter_width) + //{ + // etl::wstring<20> result_i; + // int value_i = -1234567; + + // etl::wstring<20> result_d; + // double value_d = -2.9543; + + // etl::wformat_spec format = Format().precision(4).width(6).right(); + + // etl::to_string(value_i, 1000000, result_i, format); + // etl::to_string(value_d, result_d, format); + + // CHECK_EQUAL(etl::wstring<20>(STR("-1.2345")).c_str(), result_i.c_str()); + // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + //} + + ////************************************************************************* + //TEST(test_integer_denominator_larger_width) + //{ + // etl::wstring<20> result_i; + // int value_i = -1234567; + + // etl::wstring<20> result_d; + // double value_d = -2.9543; + + // etl::wformat_spec format = Format().precision(4).width(15).right(); + + // etl::to_string(value_i, 1000000, result_i, format); + // etl::to_string(value_d, result_d, format); + + // CHECK_EQUAL(etl::wstring<20>(STR(" -1.2345")).c_str(), result_i.c_str()); + // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + //} }; } From df29374c6ea5cd48173d8779ba1c46ace4a553dc Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 29 Aug 2021 18:50:20 +0100 Subject: [PATCH 5/7] Pre-release code --- include/etl/private/to_string_helper.h | 95 ++++++------- test/test_to_string.cpp | 144 +++++++++++++++++--- test/test_to_u16string.cpp | 178 +++++++++++++++++++++---- test/test_to_u32string.cpp | 178 +++++++++++++++++++++---- test/test_to_wstring.cpp | 178 +++++++++++++++++++++---- test/vs2019/etl.vcxproj.filters | 8 +- 6 files changed, 630 insertions(+), 151 deletions(-) diff --git a/include/etl/private/to_string_helper.h b/include/etl/private/to_string_helper.h index f5cf637b..30565656 100644 --- a/include/etl/private/to_string_helper.h +++ b/include/etl/private/to_string_helper.h @@ -240,8 +240,8 @@ namespace etl /// Helper function for floating point integral and fractional. //*************************************************************************** template - void add_integral_fractional(const workspace_t integral, - const workspace_t fractional, + void add_integral_fractional(const uint32_t integral, + const uint32_t fractional, TIString& str, const etl::basic_format_spec& integral_format, const etl::basic_format_spec& fractional_format, @@ -292,7 +292,7 @@ namespace etl etl::basic_format_spec fractional_format = integral_format; fractional_format.width(integral_format.get_precision()).fill(type('0')).right(); - workspace_t multiplier = 1; + uint32_t multiplier = 1U; for (uint32_t i = 0; i < fractional_format.get_precision(); ++i) { @@ -300,17 +300,17 @@ namespace etl } // Find the integral part of the floating point - T f_integral = (value < T(0.0) ? ceil(value) : floor(value)); - workspace_t integral = etl::absolute(static_cast(f_integral)); + T f_integral = floor(etl::absolute(value)); + uint32_t integral = static_cast(f_integral); // Find the fractional part of the floating point. - workspace_t fractional = etl::absolute(static_cast(round((value - f_integral) * multiplier))); + uint32_t fractional = static_cast(round((etl::absolute(value) - f_integral) * multiplier)); // Check for a rounding carry to the integral. if (fractional == multiplier) { ++integral; - fractional = 0; + fractional = 0U; } etl::private_to_string::add_integral_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value)); @@ -324,7 +324,7 @@ namespace etl //*************************************************************************** template void add_integral_denominated(T value, - workspace_t denominator, + uint32_t denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) @@ -339,69 +339,62 @@ namespace etl iterator start = str.end(); - // Split to integral and fractional parts using the denominator - workspace_t integral = absolute(value) / denominator; - workspace_t fractional = absolute(value) % denominator; + uint32_t abs_value = etl::absolute(value); - uint32_t denominator_digits = 0U; + // Figure out how many decimal digits we have in the value. + uint32_t original_decimal_digits = 0U; uint32_t multiplier = 1U; - while (multiplier < fractional) + while (multiplier < denominator) { multiplier *= 10U; - ++denominator_digits; + ++original_decimal_digits; } + // How many decimal digits are we displaying. + uint32_t displayed_decimal_digits = (format.get_precision() > original_decimal_digits) ? original_decimal_digits : format.get_precision(); + + // Format for the integral part. etl::basic_format_spec integral_format = format; - integral_format.decimal().width(0U).precision(format.get_precision() > denominator_digits ? denominator_digits : format.get_precision()); + integral_format.decimal().width(0U); + // Format for the fractional part. etl::basic_format_spec fractional_format = integral_format; - fractional_format.width(integral_format.get_precision()).fill(type('0')).left(); + fractional_format.precision(displayed_decimal_digits).width(displayed_decimal_digits).fill(type('0')).right(); - if (fractional != 0U) + // We don't need to do this if the fractional part is zero. + if ((abs_value % denominator) != 0U) { - // Adjust the fractional with rounding. - uint32_t fractional_digits = 0U; - uint32_t multiplier = 1U; - - while (multiplier < fractional) + // Do we need to check for rounding? + if (original_decimal_digits > displayed_decimal_digits) { - multiplier *= 10U; - ++fractional_digits; - } + // Which digit to adjust? + uint32_t count = original_decimal_digits - fractional_format.get_width(); - // Do we need to round? - if (fractional_digits > fractional_format.get_width()) - { - uint32_t count = fractional_digits - fractional_format.get_width(); + // The 'round-away-from-zero' value. + uint32_t rounding = 5U; - while (count > 0U) + while (count-- > 1U) { - // Check the last digit. - if (count == 1U) - { - // Round up? - if ((fractional % 10U) >= 5U) - { - fractional += 10U; - } - } - - fractional /= 10U; - multiplier /= 10U; - - --count; + rounding *= 10U; } - } - // Check for a rounding carry to the integral. - if (fractional == multiplier) - { - ++integral; - fractional = 0U; - } + abs_value += rounding; + } } + // Split the value into integral and fractional. + uint32_t integral = abs_value / denominator; + uint32_t fractional = abs_value % denominator; + + // Move the fractional part to the right place. + uint32_t count = original_decimal_digits - fractional_format.get_width(); + while (count-- > 0U) + { + fractional /= 10U; + } + + // Create the string. etl::private_to_string::add_integral_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value)); etl::private_to_string::add_alignment(str, start, format); } diff --git a/test/test_to_string.cpp b/test/test_to_string.cpp index 9dc4bc9a..25888ba4 100644 --- a/test/test_to_string.cpp +++ b/test/test_to_string.cpp @@ -451,7 +451,7 @@ namespace etl::string<20> result; int value = -1234560; - etl::format_spec format = Format().precision(100); + Format format = Format().precision(100); etl::to_string(value, 1000000, result, format); @@ -459,20 +459,128 @@ namespace } //************************************************************************* - TEST(test_integer_denominator_shorter_width) + TEST(test_integer_denominator_zero_fractional) { etl::string<20> result_i; - int value_i = -1234560; + int value_i = -1000000; etl::string<20> result_d; - double value_d = -1.234560; + double value_d = -1.000000; - etl::format_spec format = Format().precision(4).width(6).right(); + Format format = Format().precision(4); etl::to_string(value_i, 1000000, result_i, format); etl::to_string(value_d, result_d, format); - CHECK_EQUAL(etl::string<20>(STR("-1.2346")).c_str(), result_i.c_str()); + CHECK_EQUAL(etl::string<20>(STR("-1.0000")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_zero_value) + { + etl::string<20> result_i; + int value_i = 0; + + etl::string<20> result_d; + double value_d = -0.000000; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("0.0000")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_zero_integral_small_fractional) + { + etl::string<20> result_i; + int value_i = -400; + + etl::string<20> result_d; + double value_d = -0.000400; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("-0.0004")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_small_fractional) + { + etl::string<20> result_i; + int value_i = -123000400; + + etl::string<20> result_d; + double value_d = -123.000400; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("-123.0004")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_very_small_fractional) + { + etl::string<20> result_i; + int value_i = -123000004; + + etl::string<20> result_d; + double value_d = -123.000004; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("-123.0000")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_very_small_fractional_rounded_up) + { + etl::string<20> result_i; + int value_i = -123000050; + + etl::string<20> result_d; + double value_d = -123.000050; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("-123.0001")).c_str(), result_i.c_str()); + CHECK_EQUAL(result_d.c_str(), result_i.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_shorter_width) + { + etl::string<20> result_i; + int value_i = -123456780; + + etl::string<20> result_d; + double value_d = -123.456780; + + Format format = Format().precision(4).width(6).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK_EQUAL(etl::string<20>(STR("-123.4568")).c_str(), result_i.c_str()); CHECK_EQUAL(result_d.c_str(), result_i.c_str()); } @@ -480,17 +588,17 @@ namespace TEST(test_integer_denominator_larger_width) { etl::string<20> result_i; - int value_i = -1234560; + int value_i = -123456780; etl::string<20> result_d; - double value_d = -1.234560; + double value_d = -123.456780; - etl::format_spec format = Format().precision(4).width(15).right(); + Format format = Format().precision(4).width(15).right(); etl::to_string(value_i, 1000000, result_i, format); etl::to_string(value_d, result_d, format); - CHECK_EQUAL(etl::string<20>(STR(" -1.2346")).c_str(), result_i.c_str()); + CHECK_EQUAL(etl::string<20>(STR(" -123.4568")).c_str(), result_i.c_str()); CHECK_EQUAL(result_d.c_str(), result_i.c_str()); } @@ -498,17 +606,17 @@ namespace TEST(test_integer_denominator_positive_rollover) { etl::string<20> result_i; - int value_i = 1999990; + int value_i = 123999990; etl::string<20> result_d; - double value_d = 1.999990; + double value_d = 123.999990; - etl::format_spec format = Format().precision(4).right(); + Format format = Format().precision(4).right(); etl::to_string(value_i, 1000000, result_i, format); etl::to_string(value_d, result_d, format); - CHECK_EQUAL(etl::string<20>(STR("2.0000")).c_str(), result_i.c_str()); + CHECK_EQUAL(etl::string<20>(STR("124.0000")).c_str(), result_i.c_str()); CHECK_EQUAL(result_d.c_str(), result_i.c_str()); } @@ -516,17 +624,17 @@ namespace TEST(test_integer_denominator_negative_rollover) { etl::string<20> result_i; - int value_i = -1999990; + int value_i = -123999990; etl::string<20> result_d; - double value_d = -1.999990; + double value_d = -123.999990; - etl::format_spec format = Format().precision(4).right(); + Format format = Format().precision(4).right(); etl::to_string(value_i, 1000000, result_i, format); etl::to_string(value_d, result_d, format); - CHECK_EQUAL(etl::string<20>(STR("-2.0000")).c_str(), result_i.c_str()); + CHECK_EQUAL(etl::string<20>(STR("-124.0000")).c_str(), result_i.c_str()); CHECK_EQUAL(result_d.c_str(), result_i.c_str()); } }; diff --git a/test/test_to_u16string.cpp b/test/test_to_u16string.cpp index 85b3af67..d8a55476 100644 --- a/test/test_to_u16string.cpp +++ b/test/test_to_u16string.cpp @@ -349,41 +349,167 @@ namespace CHECK(etl::u16string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); } - ////************************************************************************* - //TEST(test_integer_denominator_shorter_width) - //{ - // etl::u16string<20> result_i; - // int value_i = -1234567; + //************************************************************************* + TEST(test_integer_denominator_zero_value) + { + etl::u16string<20> result_i; + int value_i = 0; - // etl::u16string<20> result_d; - // double value_d = -2.9543; + etl::u16string<20> result_d; + double value_d = -0.000000; - // etl::u16format_spec format = Format().precision(4).width(6).right(); + Format format = Format().precision(4); - // etl::to_string(value_i, 1000000, result_i, format); - // etl::to_string(value_d, result_d, format); + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); - // CHECK_EQUAL(etl::u16string<20>(STR("-1.2346")).c_str(), result_i.c_str()); - // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); - //} + CHECK(etl::u16string<20>(STR("0.0000")) == result_i); + CHECK(result_d == result_i); + } - ////************************************************************************* - //TEST(test_integer_denominator_larger_width) - //{ - // etl::u16string<20> result_i; - // int value_i = -1234567; + //************************************************************************* + TEST(test_integer_denominator_zero_integral_small_fractional) + { + etl::u16string<20> result_i; + int value_i = -400; - // etl::u16string<20> result_d; - // double value_d = -2.9543; + etl::u16string<20> result_d; + double value_d = -0.000400; - // etl::u16format_spec format = Format().precision(4).width(15).right(); + Format format = Format().precision(4); - // etl::to_string(value_i, 1000000, result_i, format); - // etl::to_string(value_d, result_d, format); + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); - // CHECK_EQUAL(etl::u16string<20>(STR(" -1.2345")).c_str(), result_i.c_str()); - // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); - //} + CHECK(etl::u16string<20>(STR("-0.0004")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_small_fractional) + { + etl::u16string<20> result_i; + int value_i = -123000400; + + etl::u16string<20> result_d; + double value_d = -123.000400; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u16string<20>(STR("-123.0004")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_very_small_fractional) + { + etl::u16string<20> result_i; + int value_i = -123000004; + + etl::u16string<20> result_d; + double value_d = -123.000004; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u16string<20>(STR("-123.0000")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_very_small_fractional_rounded_up) + { + etl::u16string<20> result_i; + int value_i = -123000050; + + etl::u16string<20> result_d; + double value_d = -123.000050; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u16string<20>(STR("-123.0001")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_shorter_width) + { + etl::u16string<20> result_i; + int value_i = -123456780; + + etl::u16string<20> result_d; + double value_d = -123.456780; + + Format format = Format().precision(4).width(6).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u16string<20>(STR("-123.4568")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_larger_width) + { + etl::u16string<20> result_i; + int value_i = -123456780; + + etl::u16string<20> result_d; + double value_d = -123.456780; + + Format format = Format().precision(4).width(15).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u16string<20>(STR(" -123.4568")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_positive_rollover) + { + etl::u16string<20> result_i; + int value_i = 123999990; + + etl::u16string<20> result_d; + double value_d = 123.999990; + + Format format = Format().precision(4).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u16string<20>(STR("124.0000")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_negative_rollover) + { + etl::u16string<20> result_i; + int value_i = -123999990; + + etl::u16string<20> result_d; + double value_d = -123.999990; + + Format format = Format().precision(4).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u16string<20>(STR("-124.0000")) == result_i.c_str()); + CHECK(result_d == result_i); + } }; } diff --git a/test/test_to_u32string.cpp b/test/test_to_u32string.cpp index 07d9909e..bfa098c9 100644 --- a/test/test_to_u32string.cpp +++ b/test/test_to_u32string.cpp @@ -354,41 +354,167 @@ namespace CHECK(etl::u32string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); } - ////************************************************************************* - //TEST(test_integer_denominator_shorter_width) - //{ - // etl::u32string<20> result_i; - // int value_i = -1234567; + //************************************************************************* + TEST(test_integer_denominator_zero_value) + { + etl::u32string<20> result_i; + int value_i = 0; - // etl::u32string<20> result_d; - // double value_d = -2.9543; + etl::u32string<20> result_d; + double value_d = -0.000000; - // etl::u32format_spec format = Format().precision(4).width(6).right(); + Format format = Format().precision(4); - // etl::to_string(value_i, 1000000, result_i, format); - // etl::to_string(value_d, result_d, format); + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); - // CHECK_EQUAL(etl::u32string<20>(STR("-1.2345")).c_str(), result_i.c_str()); - // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); - //} + CHECK(etl::u32string<20>(STR("0.0000")) == result_i); + CHECK(result_d == result_i); + } - ////************************************************************************* - //TEST(test_integer_denominator_larger_width) - //{ - // etl::u32string<20> result_i; - // int value_i = -1234567; + //************************************************************************* + TEST(test_integer_denominator_zero_integral_small_fractional) + { + etl::u32string<20> result_i; + int value_i = -400; - // etl::u32string<20> result_d; - // double value_d = -2.9543; + etl::u32string<20> result_d; + double value_d = -0.000400; - // etl::u32format_spec format = Format().precision(4).width(15).right(); + Format format = Format().precision(4); - // etl::to_string(value_i, 1000000, result_i, format); - // etl::to_string(value_d, result_d, format); + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); - // CHECK_EQUAL(etl::u32string<20>(STR(" -1.2345")).c_str(), result_i.c_str()); - // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); - //} + CHECK(etl::u32string<20>(STR("-0.0004")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_small_fractional) + { + etl::u32string<20> result_i; + int value_i = -123000400; + + etl::u32string<20> result_d; + double value_d = -123.000400; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u32string<20>(STR("-123.0004")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_very_small_fractional) + { + etl::u32string<20> result_i; + int value_i = -123000004; + + etl::u32string<20> result_d; + double value_d = -123.000004; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u32string<20>(STR("-123.0000")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_very_small_fractional_rounded_up) + { + etl::u32string<20> result_i; + int value_i = -123000050; + + etl::u32string<20> result_d; + double value_d = -123.000050; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u32string<20>(STR("-123.0001")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_shorter_width) + { + etl::u32string<20> result_i; + int value_i = -123456780; + + etl::u32string<20> result_d; + double value_d = -123.456780; + + Format format = Format().precision(4).width(6).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u32string<20>(STR("-123.4568")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_larger_width) + { + etl::u32string<20> result_i; + int value_i = -123456780; + + etl::u32string<20> result_d; + double value_d = -123.456780; + + Format format = Format().precision(4).width(15).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u32string<20>(STR(" -123.4568")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_positive_rollover) + { + etl::u32string<20> result_i; + int value_i = 123999990; + + etl::u32string<20> result_d; + double value_d = 123.999990; + + Format format = Format().precision(4).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u32string<20>(STR("124.0000")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_negative_rollover) + { + etl::u32string<20> result_i; + int value_i = -123999990; + + etl::u32string<20> result_d; + double value_d = -123.999990; + + Format format = Format().precision(4).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u32string<20>(STR("-124.0000")) == result_i.c_str()); + CHECK(result_d == result_i); + } }; } diff --git a/test/test_to_wstring.cpp b/test/test_to_wstring.cpp index f1cc0f81..48c02d84 100644 --- a/test/test_to_wstring.cpp +++ b/test/test_to_wstring.cpp @@ -416,41 +416,167 @@ namespace CHECK(compare == str); } - ////************************************************************************* - //TEST(test_integer_denominator_shorter_width) - //{ - // etl::wstring<20> result_i; - // int value_i = -1234567; + //************************************************************************* + TEST(test_integer_denominator_zero_value) + { + etl::wstring<20> result_i; + int value_i = 0; - // etl::wstring<20> result_d; - // double value_d = -2.9543; + etl::wstring<20> result_d; + double value_d = -0.000000; - // etl::wformat_spec format = Format().precision(4).width(6).right(); + Format format = Format().precision(4); - // etl::to_string(value_i, 1000000, result_i, format); - // etl::to_string(value_d, result_d, format); + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); - // CHECK_EQUAL(etl::wstring<20>(STR("-1.2345")).c_str(), result_i.c_str()); - // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); - //} + CHECK(etl::wstring<20>(STR("0.0000")) == result_i); + CHECK(result_d == result_i); + } - ////************************************************************************* - //TEST(test_integer_denominator_larger_width) - //{ - // etl::wstring<20> result_i; - // int value_i = -1234567; + //************************************************************************* + TEST(test_integer_denominator_zero_integral_small_fractional) + { + etl::wstring<20> result_i; + int value_i = -400; - // etl::wstring<20> result_d; - // double value_d = -2.9543; + etl::wstring<20> result_d; + double value_d = -0.000400; - // etl::wformat_spec format = Format().precision(4).width(15).right(); + Format format = Format().precision(4); - // etl::to_string(value_i, 1000000, result_i, format); - // etl::to_string(value_d, result_d, format); + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); - // CHECK_EQUAL(etl::wstring<20>(STR(" -1.2345")).c_str(), result_i.c_str()); - // CHECK_EQUAL(result_d.c_str(), result_i.c_str()); - //} + CHECK(etl::wstring<20>(STR("-0.0004")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_small_fractional) + { + etl::wstring<20> result_i; + int value_i = -123000400; + + etl::wstring<20> result_d; + double value_d = -123.000400; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::wstring<20>(STR("-123.0004")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_very_small_fractional) + { + etl::wstring<20> result_i; + int value_i = -123000004; + + etl::wstring<20> result_d; + double value_d = -123.000004; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::wstring<20>(STR("-123.0000")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_very_small_fractional_rounded_up) + { + etl::wstring<20> result_i; + int value_i = -123000050; + + etl::wstring<20> result_d; + double value_d = -123.000050; + + Format format = Format().precision(4); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::wstring<20>(STR("-123.0001")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_shorter_width) + { + etl::wstring<20> result_i; + int value_i = -123456780; + + etl::wstring<20> result_d; + double value_d = -123.456780; + + Format format = Format().precision(4).width(6).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::wstring<20>(STR("-123.4568")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_larger_width) + { + etl::wstring<20> result_i; + int value_i = -123456780; + + etl::wstring<20> result_d; + double value_d = -123.456780; + + Format format = Format().precision(4).width(15).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::wstring<20>(STR(" -123.4568")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_positive_rollover) + { + etl::wstring<20> result_i; + int value_i = 123999990; + + etl::wstring<20> result_d; + double value_d = 123.999990; + + Format format = Format().precision(4).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::wstring<20>(STR("124.0000")) == result_i); + CHECK(result_d == result_i); + } + + //************************************************************************* + TEST(test_integer_denominator_negative_rollover) + { + etl::wstring<20> result_i; + int value_i = -123999990; + + etl::wstring<20> result_d; + double value_d = -123.999990; + + Format format = Format().precision(4).right(); + + etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::wstring<20>(STR("-124.0000")) == result_i.c_str()); + CHECK(result_d == result_i); + } }; } diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 3861d5c3..572a72df 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -2990,12 +2990,12 @@ Source Files\Sanity Checks - - Source Files - Source Files + + Source Files\Sanity Checks + @@ -3140,4 +3140,4 @@ Resource Files - + \ No newline at end of file From 2cd0f79db4293a80e0b00f2d05a9a5f02f6792c1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 30 Aug 2021 16:33:15 +0100 Subject: [PATCH 6/7] Working code including 64 bit --- include/etl/private/to_string_helper.h | 294 ++++++++++--------------- include/etl/to_string.h | 8 +- include/etl/to_u16string.h | 8 +- include/etl/to_u32string.h | 8 +- include/etl/to_wstring.h | 8 +- test/test_to_string.cpp | 41 ++-- test/test_to_u16string.cpp | 77 ++++++- test/test_to_u32string.cpp | 75 ++++++- test/test_to_wstring.cpp | 75 ++++++- 9 files changed, 351 insertions(+), 243 deletions(-) diff --git a/include/etl/private/to_string_helper.h b/include/etl/private/to_string_helper.h index 30565656..6876b6cc 100644 --- a/include/etl/private/to_string_helper.h +++ b/include/etl/private/to_string_helper.h @@ -88,7 +88,7 @@ namespace etl void add_boolean(const bool value, TIString& str, const etl::basic_format_spec& format, - bool append) + const bool append) { typedef typename TIString::value_type type; typedef typename TIString::iterator iterator; @@ -240,8 +240,31 @@ namespace etl /// Helper function for floating point integral and fractional. //*************************************************************************** template - void add_integral_fractional(const uint32_t integral, - const uint32_t fractional, + void add_integral_and_fractional(const uint32_t integral, + const uint32_t fractional, + TIString& str, + const etl::basic_format_spec& integral_format, + const etl::basic_format_spec& fractional_format, + const bool negative) + { + typedef typename TIString::value_type type; + + etl::private_to_string::add_integral(integral, str, integral_format, true, negative); + + if (fractional_format.get_precision() > 0) + { + str.push_back(type('.')); + etl::private_to_string::add_integral(fractional, str, fractional_format, true, false); + } + } + +#if ETL_USING_64BIT_TYPES + //*************************************************************************** + /// Helper function for floating point integral and fractional. + //*************************************************************************** + template + void add_integral_and_fractional(const uint64_t integral, + const uint64_t fractional, TIString& str, const etl::basic_format_spec& integral_format, const etl::basic_format_spec& fractional_format, @@ -257,15 +280,16 @@ namespace etl etl::private_to_string::add_integral(fractional, str, fractional_format, true, false); } } +#endif //*************************************************************************** /// Helper function for floating point. //*************************************************************************** template - void add_floating_point(T value, + void add_floating_point(const T value, TIString& str, const etl::basic_format_spec& format, - bool append) + const bool append) { typedef typename TIString::iterator iterator; typedef typename TIString::value_type type; @@ -313,24 +337,25 @@ namespace etl fractional = 0U; } - etl::private_to_string::add_integral_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value)); + etl::private_to_string::add_integral_and_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value)); } etl::private_to_string::add_alignment(str, start, format); } //*************************************************************************** - /// Helper function for divided integers. + /// Helper function for denominated integers. //*************************************************************************** template - void add_integral_denominated(T value, - uint32_t denominator, + void add_integral_denominated(const T value, + const uint32_t denominator_exponent, TIString& str, const etl::basic_format_spec& format, - bool append = false) + const bool append = false) { - typedef typename TIString::iterator iterator; - typedef typename TIString::value_type type; + typedef typename TIString::iterator iterator; + typedef typename TIString::value_type type; + typedef typename etl::make_unsigned::type working_t; if (!append) { @@ -339,20 +364,21 @@ namespace etl iterator start = str.end(); - uint32_t abs_value = etl::absolute(value); + // Caculate the denominator. + working_t denominator = 1U; - // Figure out how many decimal digits we have in the value. - uint32_t original_decimal_digits = 0U; - uint32_t multiplier = 1U; - - while (multiplier < denominator) + for (uint32_t i = 0U; i < denominator_exponent; ++i) { - multiplier *= 10U; - ++original_decimal_digits; + denominator *= 10U; } + working_t abs_value = etl::absolute(value); + + // Figure out how many decimal digits we have in the value. + const uint32_t& original_decimal_digits = denominator_exponent; + // How many decimal digits are we displaying. - uint32_t displayed_decimal_digits = (format.get_precision() > original_decimal_digits) ? original_decimal_digits : format.get_precision(); + const uint32_t displayed_decimal_digits = (format.get_precision() > original_decimal_digits) ? original_decimal_digits : format.get_precision(); // Format for the integral part. etl::basic_format_spec integral_format = format; @@ -362,30 +388,26 @@ namespace etl etl::basic_format_spec fractional_format = integral_format; fractional_format.precision(displayed_decimal_digits).width(displayed_decimal_digits).fill(type('0')).right(); - // We don't need to do this if the fractional part is zero. - if ((abs_value % denominator) != 0U) + // Do we need to check for rounding? + if (original_decimal_digits > displayed_decimal_digits) { - // Do we need to check for rounding? - if (original_decimal_digits > displayed_decimal_digits) + // Which digit to adjust? + uint32_t count = original_decimal_digits - fractional_format.get_width(); + + // The 'round-away-from-zero' value. + uint32_t rounding = 5U; + + while (count-- > 1U) { - // Which digit to adjust? - uint32_t count = original_decimal_digits - fractional_format.get_width(); + rounding *= 10U; + } - // The 'round-away-from-zero' value. - uint32_t rounding = 5U; - - while (count-- > 1U) - { - rounding *= 10U; - } - - abs_value += rounding; - } + abs_value += rounding; } // Split the value into integral and fractional. - uint32_t integral = abs_value / denominator; - uint32_t fractional = abs_value % denominator; + working_t integral = abs_value / denominator; + working_t fractional = abs_value % denominator; // Move the fractional part to the right place. uint32_t count = original_decimal_digits - fractional_format.get_width(); @@ -395,7 +417,7 @@ namespace etl } // Create the string. - etl::private_to_string::add_integral_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value)); + etl::private_to_string::add_integral_and_fractional(integral, fractional, str, integral_format, fractional_format, etl::is_negative(value)); etl::private_to_string::add_alignment(str, start, format); } @@ -406,7 +428,7 @@ namespace etl void add_pointer(const volatile void* value, TIString& str, const etl::basic_format_spec& format, - bool append) + const bool append) { uintptr_t p = reinterpret_cast(value); @@ -420,7 +442,7 @@ namespace etl void add_string(const TIString& value, TIString& str, const etl::basic_format_spec& format, - bool append) + const bool append) { if (!append) { @@ -441,7 +463,7 @@ namespace etl void add_string_view(const TSringView& value, TIString& str, const etl::basic_format_spec& format, - bool append) + const bool append) { if (!append) { @@ -464,7 +486,7 @@ namespace etl const TIString& to_string(const bool value, TIString& str, const etl::basic_format_spec& format, - bool append = false) + const bool append = false) { etl::private_to_string::add_boolean(value, str, format, append); @@ -478,193 +500,101 @@ namespace etl const TIString& to_string(const volatile void* value, TIString& str, const etl::basic_format_spec& format, - bool append = false) + const bool append = false) { etl::private_to_string::add_pointer(value, str, format, append); return str; } -#if ETL_NOT_USING_64BIT_TYPES - +#if ETL_USING_64BIT_TYPES //*************************************************************************** - /// For signed integrals less than 64 bits. + /// For integrals less than 64 bits. //*************************************************************************** template typename etl::enable_if::value && - etl::is_signed::value && - !etl::is_same::value>::value, const TIString& > ::type - to_string(const T value, TIString& str, const etl::basic_format_spec& format, bool append = false) + !etl::is_same::value && + !etl::is_one_of::value, const TIString&>::type + to_string(const T value, TIString& str, const etl::basic_format_spec& format, const bool append = false) { - etl::private_to_string::add_integral(int32_t(value), str, format, append, etl::is_negative(value)); + typedef typename etl::conditional::value, int32_t, uint32_t>::type type; + + etl::private_to_string::add_integral(type(value), str, format, append, etl::is_negative(value)); return str; } //*************************************************************************** - /// For unsigned integrals less than 64 bits. + /// For 64 bit integrals. //*************************************************************************** template typename etl::enable_if::value && - etl::is_unsigned::value && - !etl::is_same::value>::value, const TIString& > ::type - to_string(const T value, TIString& str, const etl::basic_format_spec& format, bool append = false) + !etl::is_same::value && + etl::is_one_of::value, const TIString&>::type + to_string(const T value, TIString& str, const etl::basic_format_spec& format, const bool append = false) { - etl::private_to_string::add_integral(uint32_t(value), str, format, append, false); + etl::private_to_string::add_integral(value, str, format, append, etl::is_negative(value)); return str; } //*************************************************************************** - /// For signed integrals less than 64 bits. + /// For denominated integrals less than 64 bits. + //*************************************************************************** + template + typename etl::enable_if::value && + !etl::is_same::value && + !etl::is_one_of::value, const TIString&>::type + to_string(const T value, uint32_t denominator_exponant, TIString& str, const etl::basic_format_spec& format, const bool append = false) + { + typedef typename etl::conditional::value, int32_t, uint32_t>::type type; + + etl::private_to_string::add_integral_denominated(type(value), denominator_exponant, str, format, append); + + return str; + } + + //*************************************************************************** + /// For denominated 64 bit integrals. //*************************************************************************** template typename etl::enable_if::value&& - etl::is_signed::value && - !etl::is_same::value>::value, const TIString& > ::type - to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) + !etl::is_same::value&& + etl::is_one_of::value, const TIString&>::type + to_string(const T value, uint32_t denominator_exponant, TIString& str, const etl::basic_format_spec& format, const bool append = false) { - etl::private_to_string::add_integral_denominated(int32_t(value), denominator, str, format, append, etl::is_negative(value)); + etl::private_to_string::add_integral_denominated(value, denominator_exponant, str, format, append); return str; } - - //*************************************************************************** - /// For unsigned integrals less than 64 bits. - //*************************************************************************** - template - typename etl::enable_if::value&& - etl::is_unsigned::value && - !etl::is_same::value>::value, const TIString& > ::type - to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) - { - etl::private_to_string::add_integral_denominated(uint32_t(value), denominator, str, format, append, false); - - return str; - } - #else - //*************************************************************************** - /// For signed integrals less than 64 bits. + /// For integrals less than 64 bits. //*************************************************************************** template typename etl::enable_if::value && - etl::is_signed::value && - !etl::is_same::value && - !etl::is_same::value, const TIString&>::type - to_string(const T value, TIString& str, const etl::basic_format_spec& format, bool append = false) + !etl::is_same::value>::value, const TIString& > ::type + to_string(const T value, TIString& str, const etl::basic_format_spec& format, const bool append = false) { - etl::private_to_string::add_integral(int32_t(value), str, format, append, etl::is_negative(value)); + typedef typename etl::conditional::value, int32_t, uint32_t>::type type; + + etl::private_to_string::add_integral(type(value), str, format, append, false); return str; } //*************************************************************************** - /// For unsigned integrals less than 64 bits. + /// For denominated integrals less than 64 bits. //*************************************************************************** template typename etl::enable_if::value && - etl::is_unsigned::value && - !etl::is_same::value && - !etl::is_same::value, const TIString&>::type - to_string(const T value, TIString& str, const etl::basic_format_spec& format, bool append = false) + !etl::is_same::value>::value, const TIString& > ::type + to_string(const T value, uint32_t denominator_exponant, TIString& str, const etl::basic_format_spec& format, const bool append = false) { - etl::private_to_string::add_integral(uint32_t(value), str, format, append, false); + etl::private_to_string::add_integral_denominated(type(value), denominator_exponant, str, format, append, false); return str; } - - //*************************************************************************** - /// For signed 64 bit integrals. - //*************************************************************************** - template - typename etl::enable_if::value && - etl::is_signed::value && - !etl::is_same::value && - etl::is_same::value, const TIString&>::type - to_string(const T value, TIString& str, const etl::basic_format_spec& format, bool append = false) - { - etl::private_to_string::add_integral(int64_t(value), str, format, append, etl::is_negative(value)); - - return str; - } - - //*************************************************************************** - /// For unsigned 64 bit integrals. - //*************************************************************************** - template - typename etl::enable_if::value && - etl::is_unsigned::value && - !etl::is_same::value && - etl::is_same::value, const TIString&>::type - to_string(const T value, TIString& str, const etl::basic_format_spec& format, bool append = false) - { - etl::private_to_string::add_integral(uint64_t(value), str, format, append, false); - - return str; - } - - //*************************************************************************** - /// For signed integrals less than 64 bits. - //*************************************************************************** - template - typename etl::enable_if::value&& - etl::is_signed::value && - !etl::is_same::value && - !etl::is_same::value, const TIString&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) - { - etl::private_to_string::add_integral_denominated(int32_t(value), denominator, str, format, append); - - return str; - } - - //*************************************************************************** - /// For unsigned integrals less than 64 bits. - //*************************************************************************** - template - typename etl::enable_if::value&& - etl::is_unsigned::value && - !etl::is_same::value && - !etl::is_same::value, const TIString&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) - { - etl::private_to_string::add_integral_denominated(uint32_t(value), denominator, str, format, append); - - return str; - } - - //*************************************************************************** - /// For signed 64 bit integrals. - //*************************************************************************** - template - typename etl::enable_if::value&& - etl::is_signed::value && - !etl::is_same::value&& - etl::is_same::value, const TIString&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) - { - etl::private_to_string::add_integral_denominated(int64_t(value), denominator, str, format, append, etl::is_negative(value)); - - return str; - } - - //*************************************************************************** - /// For unsigned 64 bit integrals. - //*************************************************************************** - template - typename etl::enable_if::value&& - etl::is_unsigned::value && - !etl::is_same::value&& - etl::is_same::value, const TIString&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, TIString& str, const etl::basic_format_spec& format, bool append = false) - { - etl::private_to_string::add_integral(uint64_t(value), denominator, str, format, append, false); - - return str; - } - #endif //*************************************************************************** @@ -672,7 +602,7 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value, const TIString&>::type - to_string(const T value, TIString& str, const etl::basic_format_spec& format, bool append = false) + to_string(const T value, TIString& str, const etl::basic_format_spec& format, const bool append = false) { etl::private_to_string::add_floating_point(value, str, format, append); diff --git a/include/etl/to_string.h b/include/etl/to_string.h index de09aec2..274f26ea 100644 --- a/include/etl/to_string.h +++ b/include/etl/to_string.h @@ -71,11 +71,11 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value && !etl::is_same::value, const etl::istring&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, etl::istring& str, bool append = false) + to_string(const T value, uint32_t denominator_exponent, etl::istring& str, bool append = false) { etl::format_spec format; - return private_to_string::to_string(value, denominator, str, format, append); + return private_to_string::to_string(value, denominator_exponent, str, format, append); } //*************************************************************************** @@ -84,9 +84,9 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value && !etl::is_same::value, const etl::istring&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, etl::istring& str, const etl::format_spec& format, bool append = false) + to_string(const T value, uint32_t denominator_exponent, etl::istring& str, const etl::format_spec& format, bool append = false) { - return private_to_string::to_string(value, denominator, str, format, append); + return private_to_string::to_string(value, denominator_exponent, str, format, append); } //*************************************************************************** diff --git a/include/etl/to_u16string.h b/include/etl/to_u16string.h index 9d117aa2..0765f7b8 100644 --- a/include/etl/to_u16string.h +++ b/include/etl/to_u16string.h @@ -71,11 +71,11 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value && !etl::is_same::value, const etl::iu16string&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, etl::iu16string& str, bool append = false) + to_string(const T value, uint32_t denominator_exponent, etl::iu16string& str, bool append = false) { etl::u16format_spec format; - return private_to_string::to_string(value, denominator, str, format, append); + return private_to_string::to_string(value, denominator_exponent, str, format, append); } //*************************************************************************** @@ -84,9 +84,9 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value && !etl::is_same::value, const etl::iu16string&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, etl::iu16string& str, const etl::u16format_spec& format, bool append = false) + to_string(const T value, uint32_t denominator_exponent, etl::iu16string& str, const etl::u16format_spec& format, bool append = false) { - return private_to_string::to_string(value, denominator, str, format, append); + return private_to_string::to_string(value, denominator_exponent, str, format, append); } diff --git a/include/etl/to_u32string.h b/include/etl/to_u32string.h index a17e6ba8..08c6cc06 100644 --- a/include/etl/to_u32string.h +++ b/include/etl/to_u32string.h @@ -71,11 +71,11 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value && !etl::is_same::value, const etl::iu32string&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, etl::iu32string& str, bool append = false) + to_string(const T value, uint32_t denominator_exponent, etl::iu32string& str, bool append = false) { etl::u32format_spec format; - return private_to_string::to_string(value, denominator, str, format, append); + return private_to_string::to_string(value, denominator_exponent, str, format, append); } //*************************************************************************** @@ -84,9 +84,9 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value && !etl::is_same::value, const etl::iu32string&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, etl::iu32string& str, const etl::u32format_spec& format, bool append = false) + to_string(const T value, uint32_t denominator_exponent, etl::iu32string& str, const etl::u32format_spec& format, bool append = false) { - return private_to_string::to_string(value, denominator, str, format, append); + return private_to_string::to_string(value, denominator_exponent, str, format, append); } //*************************************************************************** diff --git a/include/etl/to_wstring.h b/include/etl/to_wstring.h index 7f710674..a6bf4b64 100644 --- a/include/etl/to_wstring.h +++ b/include/etl/to_wstring.h @@ -71,11 +71,11 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value && !etl::is_same::value, const etl::iwstring&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, etl::iwstring& str, bool append = false) + to_string(const T value, uint32_t denominator_exponent, etl::iwstring& str, bool append = false) { etl::wformat_spec format; - return private_to_string::to_string(value, denominator, str, format, append); + return private_to_string::to_string(value, denominator_exponent, str, format, append); } //*************************************************************************** @@ -84,9 +84,9 @@ namespace etl //*************************************************************************** template typename etl::enable_if::value && !etl::is_same::value, const etl::iwstring&>::type - to_string(const T value, typename etl::make_unsigned::type denominator, etl::iwstring& str, const etl::wformat_spec& format, bool append = false) + to_string(const T value, uint32_t denominator_exponent, etl::iwstring& str, const etl::wformat_spec& format, bool append = false) { - return private_to_string::to_string(value, denominator, str, format, append); + return private_to_string::to_string(value, denominator_exponent, str, format, append); } //*************************************************************************** diff --git a/test/test_to_string.cpp b/test/test_to_string.cpp index 25888ba4..440915ca 100644 --- a/test/test_to_string.cpp +++ b/test/test_to_string.cpp @@ -440,9 +440,9 @@ namespace etl::string<20> result; int value = -1234567; - etl::to_string(value, 1000000, result); + etl::to_string(value, 6U, result); - CHECK_EQUAL(etl::string<20>("-1").c_str(), result.c_str()); + CHECK_EQUAL(etl::string<20>(STR("-1")).c_str(), result.c_str()); } //************************************************************************* @@ -453,9 +453,22 @@ namespace Format format = Format().precision(100); - etl::to_string(value, 1000000, result, format); + etl::to_string(value, 6U, result, format); - CHECK_EQUAL(etl::string<20>("-1.234560").c_str(), result.c_str()); + CHECK_EQUAL(etl::string<20>(STR("-1.234560")).c_str(), result.c_str()); + } + + //************************************************************************* + TEST(test_integer_denominator_huge_precision_64bit) + { + etl::string<20> result; + int64_t value = -9223372036854775808LL; + + Format format = Format().precision(100); + + etl::to_string(value, 12U, result, format); + + CHECK_EQUAL(etl::string<20>(STR("-9223372.036854775808")).c_str(), result.c_str()); } //************************************************************************* @@ -469,7 +482,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("-1.0000")).c_str(), result_i.c_str()); @@ -487,7 +500,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("0.0000")).c_str(), result_i.c_str()); @@ -505,7 +518,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("-0.0004")).c_str(), result_i.c_str()); @@ -523,7 +536,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("-123.0004")).c_str(), result_i.c_str()); @@ -541,7 +554,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("-123.0000")).c_str(), result_i.c_str()); @@ -559,7 +572,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("-123.0001")).c_str(), result_i.c_str()); @@ -577,7 +590,7 @@ namespace Format format = Format().precision(4).width(6).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("-123.4568")).c_str(), result_i.c_str()); @@ -595,7 +608,7 @@ namespace Format format = Format().precision(4).width(15).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR(" -123.4568")).c_str(), result_i.c_str()); @@ -613,7 +626,7 @@ namespace Format format = Format().precision(4).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("124.0000")).c_str(), result_i.c_str()); @@ -631,7 +644,7 @@ namespace Format format = Format().precision(4).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK_EQUAL(etl::string<20>(STR("-124.0000")).c_str(), result_i.c_str()); diff --git a/test/test_to_u16string.cpp b/test/test_to_u16string.cpp index d8a55476..b8f364de 100644 --- a/test/test_to_u16string.cpp +++ b/test/test_to_u16string.cpp @@ -349,6 +349,61 @@ namespace CHECK(etl::u16string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); } + //************************************************************************* + TEST(test_integer_denominator_default_format) + { + etl::u16string<20> result; + int value = -1234567; + + etl::to_string(value, 6U, result); + + CHECK(etl::u16string<20>(STR("-1")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_huge_precision) + { + etl::u16string<20> result; + int value = -1234560; + + Format format = Format().precision(100); + + etl::to_string(value, 6U, result, format); + + CHECK(etl::u16string<20>(STR("-1.234560")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_huge_precision_64bit) + { + etl::u16string<20> result; + int64_t value = -9223372036854775808LL; + + Format format = Format().precision(100); + + etl::to_string(value, 12U, result, format); + + CHECK(etl::u16string<20>(STR("-9223372.036854775808")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_zero_fractional) + { + etl::u16string<20> result_i; + int value_i = -1000000; + + etl::u16string<20> result_d; + double value_d = -1.000000; + + Format format = Format().precision(4); + + etl::to_string(value_i, 6U, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u16string<20>(STR("-1.0000")) == result_i); + CHECK(result_d == result_i); + } + //************************************************************************* TEST(test_integer_denominator_zero_value) { @@ -360,7 +415,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u16string<20>(STR("0.0000")) == result_i); @@ -378,11 +433,11 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u16string<20>(STR("-0.0004")) == result_i); - CHECK(result_d == result_i); + CHECK(result_d == result_i); } //************************************************************************* @@ -396,7 +451,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u16string<20>(STR("-123.0004")) == result_i); @@ -414,7 +469,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u16string<20>(STR("-123.0000")) == result_i); @@ -432,7 +487,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u16string<20>(STR("-123.0001")) == result_i); @@ -450,7 +505,7 @@ namespace Format format = Format().precision(4).width(6).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u16string<20>(STR("-123.4568")) == result_i); @@ -468,7 +523,7 @@ namespace Format format = Format().precision(4).width(15).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u16string<20>(STR(" -123.4568")) == result_i); @@ -486,7 +541,7 @@ namespace Format format = Format().precision(4).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u16string<20>(STR("124.0000")) == result_i); @@ -504,10 +559,10 @@ namespace Format format = Format().precision(4).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); - CHECK(etl::u16string<20>(STR("-124.0000")) == result_i.c_str()); + CHECK(etl::u16string<20>(STR("-124.0000")) == result_i); CHECK(result_d == result_i); } }; diff --git a/test/test_to_u32string.cpp b/test/test_to_u32string.cpp index bfa098c9..e8ac328f 100644 --- a/test/test_to_u32string.cpp +++ b/test/test_to_u32string.cpp @@ -354,6 +354,61 @@ namespace CHECK(etl::u32string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true)); } + //************************************************************************* + TEST(test_integer_denominator_default_format) + { + etl::u32string<20> result; + int value = -1234567; + + etl::to_string(value, 6U, result); + + CHECK(etl::u32string<20>(STR("-1")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_huge_precision) + { + etl::u32string<20> result; + int value = -1234560; + + Format format = Format().precision(100); + + etl::to_string(value, 6U, result, format); + + CHECK(etl::u32string<20>(STR("-1.234560")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_huge_precision_64bit) + { + etl::u32string<20> result; + int64_t value = -9223372036854775808LL; + + Format format = Format().precision(100); + + etl::to_string(value, 12U, result, format); + + CHECK(etl::u32string<20>(STR("-9223372.036854775808")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_zero_fractional) + { + etl::u32string<20> result_i; + int value_i = -1000000; + + etl::u32string<20> result_d; + double value_d = -1.000000; + + Format format = Format().precision(4); + + etl::to_string(value_i, 6U, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::u32string<20>(STR("-1.0000")) == result_i); + CHECK(result_d == result_i); + } + //************************************************************************* TEST(test_integer_denominator_zero_value) { @@ -365,7 +420,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u32string<20>(STR("0.0000")) == result_i); @@ -383,7 +438,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u32string<20>(STR("-0.0004")) == result_i); @@ -401,7 +456,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u32string<20>(STR("-123.0004")) == result_i); @@ -419,7 +474,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u32string<20>(STR("-123.0000")) == result_i); @@ -437,7 +492,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u32string<20>(STR("-123.0001")) == result_i); @@ -455,7 +510,7 @@ namespace Format format = Format().precision(4).width(6).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u32string<20>(STR("-123.4568")) == result_i); @@ -473,7 +528,7 @@ namespace Format format = Format().precision(4).width(15).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u32string<20>(STR(" -123.4568")) == result_i); @@ -491,7 +546,7 @@ namespace Format format = Format().precision(4).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::u32string<20>(STR("124.0000")) == result_i); @@ -509,10 +564,10 @@ namespace Format format = Format().precision(4).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); - CHECK(etl::u32string<20>(STR("-124.0000")) == result_i.c_str()); + CHECK(etl::u32string<20>(STR("-124.0000")) == result_i); CHECK(result_d == result_i); } }; diff --git a/test/test_to_wstring.cpp b/test/test_to_wstring.cpp index 48c02d84..35ecf78e 100644 --- a/test/test_to_wstring.cpp +++ b/test/test_to_wstring.cpp @@ -416,6 +416,61 @@ namespace CHECK(compare == str); } + //************************************************************************* + TEST(test_integer_denominator_default_format) + { + etl::wstring<20> result; + int value = -1234567; + + etl::to_string(value, 6U, result); + + CHECK(etl::wstring<20>(STR("-1")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_huge_precision) + { + etl::wstring<20> result; + int value = -1234560; + + Format format = Format().precision(100); + + etl::to_string(value, 6U, result, format); + + CHECK(etl::wstring<20>(STR("-1.234560")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_huge_precision_64bit) + { + etl::wstring<20> result; + int64_t value = -9223372036854775808LL; + + Format format = Format().precision(100); + + etl::to_string(value, 12U, result, format); + + CHECK(etl::wstring<20>(STR("-9223372.036854775808")) == result); + } + + //************************************************************************* + TEST(test_integer_denominator_zero_fractional) + { + etl::wstring<20> result_i; + int value_i = -1000000; + + etl::wstring<20> result_d; + double value_d = -1.000000; + + Format format = Format().precision(4); + + etl::to_string(value_i, 6U, result_i, format); + etl::to_string(value_d, result_d, format); + + CHECK(etl::wstring<20>(STR("-1.0000")) == result_i); + CHECK(result_d == result_i); + } + //************************************************************************* TEST(test_integer_denominator_zero_value) { @@ -427,7 +482,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::wstring<20>(STR("0.0000")) == result_i); @@ -445,7 +500,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::wstring<20>(STR("-0.0004")) == result_i); @@ -463,7 +518,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::wstring<20>(STR("-123.0004")) == result_i); @@ -481,7 +536,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::wstring<20>(STR("-123.0000")) == result_i); @@ -499,7 +554,7 @@ namespace Format format = Format().precision(4); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::wstring<20>(STR("-123.0001")) == result_i); @@ -517,7 +572,7 @@ namespace Format format = Format().precision(4).width(6).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::wstring<20>(STR("-123.4568")) == result_i); @@ -535,7 +590,7 @@ namespace Format format = Format().precision(4).width(15).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::wstring<20>(STR(" -123.4568")) == result_i); @@ -553,7 +608,7 @@ namespace Format format = Format().precision(4).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); CHECK(etl::wstring<20>(STR("124.0000")) == result_i); @@ -571,10 +626,10 @@ namespace Format format = Format().precision(4).right(); - etl::to_string(value_i, 1000000, result_i, format); + etl::to_string(value_i, 6U, result_i, format); etl::to_string(value_d, result_d, format); - CHECK(etl::wstring<20>(STR("-124.0000")) == result_i.c_str()); + CHECK(etl::wstring<20>(STR("-124.0000")) == result_i); CHECK(result_d == result_i); } }; From 9a2108b98262e8709c0f890be262680d17602dd1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 1 Sep 2021 16:46:58 +0100 Subject: [PATCH 7/7] Modified constant definitions --- test/test_to_string.cpp | 126 ++++++++++++++++++------------------- test/test_to_u16string.cpp | 126 ++++++++++++++++++------------------- test/test_to_u32string.cpp | 126 ++++++++++++++++++------------------- test/test_to_wstring.cpp | 126 ++++++++++++++++++------------------- 4 files changed, 252 insertions(+), 252 deletions(-) diff --git a/test/test_to_string.cpp b/test/test_to_string.cpp index 440915ca..6f72985e 100644 --- a/test/test_to_string.cpp +++ b/test/test_to_string.cpp @@ -69,15 +69,15 @@ namespace CHECK(etl::string<20>(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str)); CHECK(etl::string<20>(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str)); - CHECK(etl::string<20>(STR("127")) == etl::to_string(int8_t(127), str)); - CHECK(etl::string<20>(STR("32767")) == etl::to_string(int16_t(32767), str)); - CHECK(etl::string<20>(STR("2147483647")) == etl::to_string(int32_t(2147483647ll), str)); - CHECK(etl::string<20>(STR("9223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str)); + CHECK(etl::string<20>(STR("127")) == etl::to_string(int8_t(INT8_MAX), str)); + CHECK(etl::string<20>(STR("32767")) == etl::to_string(int16_t(INT16_MAX), str)); + CHECK(etl::string<20>(STR("2147483647")) == etl::to_string(int32_t(INT32_MAX), str)); + CHECK(etl::string<20>(STR("9223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str)); - CHECK(etl::string<20>(STR("-128")) == etl::to_string(int8_t(-128), str)); - CHECK(etl::string<20>(STR("-32768")) == etl::to_string(int16_t(-32768), str)); - CHECK(etl::string<20>(STR("-2147483648")) == etl::to_string(int32_t(-2147483648ll), str)); - CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str)); + CHECK(etl::string<20>(STR("-128")) == etl::to_string(int8_t(INT8_MIN), str)); + CHECK(etl::string<20>(STR("-32768")) == etl::to_string(int16_t(INT16_MIN), str)); + CHECK(etl::string<20>(STR("-2147483648")) == etl::to_string(int32_t(INT32_MIN), str)); + CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str)); } //************************************************************************* @@ -85,7 +85,7 @@ namespace { etl::string<120> str; - CHECK(etl::string<120>(STR("0")) == etl::to_string(uint8_t(0), str, true)); + CHECK(etl::string<120>(STR("0")) == etl::to_string(uint8_t(0), str, true)); CHECK(etl::string<120>(STR("00")) == etl::to_string(uint16_t(0), str, true)); CHECK(etl::string<120>(STR("000")) == etl::to_string(uint32_t(0), str, true)); CHECK(etl::string<120>(STR("0000")) == etl::to_string(uint64_t(0), str, true)); @@ -95,15 +95,15 @@ namespace CHECK(etl::string<120>(STR("0000128327682147483648")) == etl::to_string(uint32_t(2147483648ul), str, true)); CHECK(etl::string<120>(STR("00001283276821474836489223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, true)); - CHECK(etl::string<120>(STR("00001283276821474836489223372036854775808127")) == etl::to_string(int8_t(127), str, true)); - CHECK(etl::string<120>(STR("0000128327682147483648922337203685477580812732767")) == etl::to_string(int16_t(32767), str, true)); - CHECK(etl::string<120>(STR("00001283276821474836489223372036854775808127327672147483647")) == etl::to_string(int32_t(2147483647ll), str, true)); - CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str, true)); + CHECK(etl::string<120>(STR("00001283276821474836489223372036854775808127")) == etl::to_string(int8_t(INT8_MAX), str, true)); + CHECK(etl::string<120>(STR("0000128327682147483648922337203685477580812732767")) == etl::to_string(int16_t(INT16_MAX), str, true)); + CHECK(etl::string<120>(STR("00001283276821474836489223372036854775808127327672147483647")) == etl::to_string(int32_t(INT32_MAX), str, true)); + CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str, true)); - CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")) == etl::to_string(int8_t(-128), str, true)); - CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")) == etl::to_string(int16_t(-32768), str, true)); - CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")) == etl::to_string(int32_t(-2147483648ll), str, true)); - CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, true)); + CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")) == etl::to_string(int8_t(INT8_MIN), str, true)); + CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")) == etl::to_string(int16_t(INT16_MIN), str, true)); + CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")) == etl::to_string(int32_t(INT32_MIN), str, true)); + CHECK(etl::string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, true)); } //************************************************************************* @@ -115,7 +115,7 @@ namespace etl::to_string(uint8_t(0), str, format); - CHECK(etl::string<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format)); + CHECK(etl::string<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format)); CHECK(etl::string<20>(STR("###################0")) == etl::to_string(uint16_t(0), str, format)); CHECK(etl::string<20>(STR("###################0")) == etl::to_string(uint32_t(0), str, format)); CHECK(etl::string<20>(STR("###################0")) == etl::to_string(uint64_t(0), str, format)); @@ -125,15 +125,15 @@ namespace CHECK(etl::string<20>(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format)); CHECK(etl::string<20>(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format)); - CHECK(etl::string<20>(STR("#################127")) == etl::to_string(int8_t(127), str, format)); - CHECK(etl::string<20>(STR("###############32767")) == etl::to_string(int16_t(32767), str, format)); - CHECK(etl::string<20>(STR("##########2147483647")) == etl::to_string(int32_t(2147483647ll), str, format)); - CHECK(etl::string<20>(STR("#9223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str, format)); + CHECK(etl::string<20>(STR("#################127")) == etl::to_string(int8_t(INT8_MAX), str, format)); + CHECK(etl::string<20>(STR("###############32767")) == etl::to_string(int16_t(INT16_MAX), str, format)); + CHECK(etl::string<20>(STR("##########2147483647")) == etl::to_string(int32_t(INT32_MAX), str, format)); + CHECK(etl::string<20>(STR("#9223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str, format)); - CHECK(etl::string<20>(STR("################-128")) == etl::to_string(int8_t(-128), str, format)); - CHECK(etl::string<20>(STR("##############-32768")) == etl::to_string(int16_t(-32768), str, format)); - CHECK(etl::string<20>(STR("#########-2147483648")) == etl::to_string(int32_t(-2147483648ll), str, format)); - CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, format)); + CHECK(etl::string<20>(STR("################-128")) == etl::to_string(int8_t(INT8_MIN), str, format)); + CHECK(etl::string<20>(STR("##############-32768")) == etl::to_string(int16_t(INT16_MIN), str, format)); + CHECK(etl::string<20>(STR("#########-2147483648")) == etl::to_string(int32_t(INT32_MIN), str, format)); + CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, format)); } //************************************************************************* @@ -143,7 +143,7 @@ namespace Format format = Format().base(10).width(20).fill(STR('#')).left(); - CHECK(etl::string<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format)); + CHECK(etl::string<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format)); CHECK(etl::string<20>(STR("0###################")) == etl::to_string(uint16_t(0), str, format)); CHECK(etl::string<20>(STR("0###################")) == etl::to_string(uint32_t(0), str, format)); CHECK(etl::string<20>(STR("0###################")) == etl::to_string(uint64_t(0), str, format)); @@ -153,15 +153,15 @@ namespace CHECK(etl::string<20>(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format)); CHECK(etl::string<20>(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format)); - CHECK(etl::string<20>(STR("127#################")) == etl::to_string(int8_t(127), str, format)); - CHECK(etl::string<20>(STR("32767###############")) == etl::to_string(int16_t(32767), str, format)); - CHECK(etl::string<20>(STR("2147483647##########")) == etl::to_string(int32_t(2147483647ll), str, format)); - CHECK(etl::string<20>(STR("9223372036854775807#")) == etl::to_string(int64_t(9223372036854775807ll), str, format)); + CHECK(etl::string<20>(STR("127#################")) == etl::to_string(int8_t(INT8_MAX), str, format)); + CHECK(etl::string<20>(STR("32767###############")) == etl::to_string(int16_t(INT16_MAX), str, format)); + CHECK(etl::string<20>(STR("2147483647##########")) == etl::to_string(int32_t(INT32_MAX), str, format)); + CHECK(etl::string<20>(STR("9223372036854775807#")) == etl::to_string(int64_t(INT64_MAX), str, format)); - CHECK(etl::string<20>(STR("-128################")) == etl::to_string(int8_t(-128), str, format)); - CHECK(etl::string<20>(STR("-32768##############")) == etl::to_string(int16_t(-32768), str, format)); - CHECK(etl::string<20>(STR("-2147483648#########")) == etl::to_string(int32_t(-2147483648ll), str, format)); - CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, format)); + CHECK(etl::string<20>(STR("-128################")) == etl::to_string(int8_t(INT8_MIN), str, format)); + CHECK(etl::string<20>(STR("-32768##############")) == etl::to_string(int16_t(INT16_MIN), str, format)); + CHECK(etl::string<20>(STR("-2147483648#########")) == etl::to_string(int32_t(INT32_MIN), str, format)); + CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, format)); } //************************************************************************* @@ -169,7 +169,7 @@ namespace { etl::string<64> str; - CHECK(etl::string<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::string<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0')))); CHECK(etl::string<64>(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0')))); CHECK(etl::string<64>(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0')))); CHECK(etl::string<64>(STR("0000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0')))); @@ -179,15 +179,15 @@ namespace CHECK(etl::string<64>(STR("10000000000000000000000000000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0')))); CHECK(etl::string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(2).width(64).fill(STR('0')))); - CHECK(etl::string<64>(STR("01111111")) == etl::to_string(int8_t(127), str, Format().base(2).width(8).fill(STR('0')))); - CHECK(etl::string<64>(STR("0111111111111111")) == etl::to_string(int16_t(32767), str, Format().base(2).width(16).fill(STR('0')))); - CHECK(etl::string<64>(STR("01111111111111111111111111111111")) == etl::to_string(int32_t(2147483647ll), str, Format().base(2).width(32).fill(STR('0')))); - CHECK(etl::string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(2).width(64).fill(STR('0')))); + CHECK(etl::string<64>(STR("01111111")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::string<64>(STR("0111111111111111")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(2).width(16).fill(STR('0')))); + CHECK(etl::string<64>(STR("01111111111111111111111111111111")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(2).width(32).fill(STR('0')))); + CHECK(etl::string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(2).width(64).fill(STR('0')))); - CHECK(etl::string<64>(STR("10000000")) == etl::to_string(int8_t(-128), str, Format().base(2).width(8).fill(STR('0')))); - CHECK(etl::string<64>(STR("1000000000000000")) == etl::to_string(int16_t(-32768), str, Format().base(2).width(16).fill(STR('0')))); - CHECK(etl::string<64>(STR("10000000000000000000000000000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(2).width(32).fill(STR('0')))); - CHECK(etl::string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(2).width(64).fill(STR('0')))); + CHECK(etl::string<64>(STR("10000000")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::string<64>(STR("1000000000000000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(2).width(16).fill(STR('0')))); + CHECK(etl::string<64>(STR("10000000000000000000000000000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(2).width(32).fill(STR('0')))); + CHECK(etl::string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(2).width(64).fill(STR('0')))); } //************************************************************************* @@ -195,7 +195,7 @@ namespace { etl::string<22> str; - CHECK(etl::string<22>(STR("000")) == etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::string<22>(STR("000")) == etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0')))); CHECK(etl::string<22>(STR("000000")) == etl::to_string(uint16_t(0), str, Format().base(8).width(6).fill(STR('0')))); CHECK(etl::string<22>(STR("00000000000")) == etl::to_string(uint32_t(0), str, Format().base(8).width(11).fill(STR('0')))); CHECK(etl::string<22>(STR("0000000000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(8).width(22).fill(STR('0')))); @@ -205,15 +205,15 @@ namespace CHECK(etl::string<22>(STR("20000000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(8).width(11).fill(STR('0')))); CHECK(etl::string<22>(STR("1000000000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(8).width(22).fill(STR('0')))); - CHECK(etl::string<22>(STR("177")) == etl::to_string(int8_t(127), str, Format().base(8).width(3).fill(STR('0')))); - CHECK(etl::string<22>(STR("077777")) == etl::to_string(int16_t(32767), str, Format().base(8).width(6).fill(STR('0')))); - CHECK(etl::string<22>(STR("17777777777")) == etl::to_string(int32_t(2147483647ll), str, Format().base(8).width(11).fill(STR('0')))); - CHECK(etl::string<22>(STR("0777777777777777777777")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(8).width(22).fill(STR('0')))); + CHECK(etl::string<22>(STR("177")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::string<22>(STR("077777")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(8).width(6).fill(STR('0')))); + CHECK(etl::string<22>(STR("17777777777")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(8).width(11).fill(STR('0')))); + CHECK(etl::string<22>(STR("0777777777777777777777")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(8).width(22).fill(STR('0')))); - CHECK(etl::string<22>(STR("200")) == etl::to_string(int8_t(-128), str, Format().base(8).width(3).fill(STR('0')))); - CHECK(etl::string<22>(STR("100000")) == etl::to_string(int16_t(-32768), str, Format().base(8).width(6).fill(STR('0')))); - CHECK(etl::string<22>(STR("20000000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(8).width(11).fill(STR('0')))); - CHECK(etl::string<22>(STR("1000000000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(8).width(22).fill(STR('0')))); + CHECK(etl::string<22>(STR("200")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::string<22>(STR("100000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(8).width(6).fill(STR('0')))); + CHECK(etl::string<22>(STR("20000000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(8).width(11).fill(STR('0')))); + CHECK(etl::string<22>(STR("1000000000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(8).width(22).fill(STR('0')))); } //************************************************************************* @@ -221,7 +221,7 @@ namespace { etl::string<16> str; - CHECK(etl::string<16>(STR("00")) == etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::string<16>(STR("00")) == etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0')))); CHECK(etl::string<16>(STR("0000")) == etl::to_string(uint16_t(0), str, Format().base(16).width(4).fill(STR('0')))); CHECK(etl::string<16>(STR("00000000")) == etl::to_string(uint32_t(0), str, Format().base(16).width(8).fill(STR('0')))); CHECK(etl::string<16>(STR("0000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(16).width(16).fill(STR('0')))); @@ -231,15 +231,15 @@ namespace CHECK(etl::string<16>(STR("80000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(16).width(8).fill(STR('0')))); CHECK(etl::string<16>(STR("8000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(16).width(16).fill(STR('0')))); - CHECK(etl::string<16>(STR("7f")) == etl::to_string(int8_t(127), str, Format().base(16).width(2).fill(STR('0')))); - CHECK(etl::string<16>(STR("7fff")) == etl::to_string(int16_t(32767), str, Format().base(16).width(4).fill(STR('0')))); - CHECK(etl::string<16>(STR("7fffffff")) == etl::to_string(int32_t(2147483647ll), str, Format().base(16).width(8).fill(STR('0')))); - CHECK(etl::string<16>(STR("7fffffffffffffff")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(16).width(16).fill(STR('0')))); + CHECK(etl::string<16>(STR("7f")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::string<16>(STR("7fff")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(16).width(4).fill(STR('0')))); + CHECK(etl::string<16>(STR("7fffffff")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(16).width(8).fill(STR('0')))); + CHECK(etl::string<16>(STR("7fffffffffffffff")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(16).width(16).fill(STR('0')))); - CHECK(etl::string<16>(STR("80")) == etl::to_string(int8_t(-128), str, Format().base(16).width(2).fill(STR('0')))); - CHECK(etl::string<16>(STR("8000")) == etl::to_string(int16_t(-32768), str, Format().base(16).width(4).fill(STR('0')))); - CHECK(etl::string<16>(STR("80000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0')))); - CHECK(etl::string<16>(STR("8000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(16).width(16).fill(STR('0')))); + CHECK(etl::string<16>(STR("80")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::string<16>(STR("8000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(16).width(4).fill(STR('0')))); + CHECK(etl::string<16>(STR("80000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(16).width(8).fill(STR('0')))); + CHECK(etl::string<16>(STR("8000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(16).width(16).fill(STR('0')))); } //************************************************************************* @@ -462,7 +462,7 @@ namespace TEST(test_integer_denominator_huge_precision_64bit) { etl::string<20> result; - int64_t value = -9223372036854775808LL; + int64_t value = INT64_MIN; Format format = Format().precision(100); diff --git a/test/test_to_u16string.cpp b/test/test_to_u16string.cpp index b8f364de..af9761b6 100644 --- a/test/test_to_u16string.cpp +++ b/test/test_to_u16string.cpp @@ -56,15 +56,15 @@ namespace CHECK(etl::u16string<20>(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str)); CHECK(etl::u16string<20>(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str)); - CHECK(etl::u16string<20>(STR("127")) == etl::to_string(int8_t(127), str)); - CHECK(etl::u16string<20>(STR("32767")) == etl::to_string(int16_t(32767), str)); - CHECK(etl::u16string<20>(STR("2147483647")) == etl::to_string(int32_t(2147483647ll), str)); - CHECK(etl::u16string<20>(STR("9223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str)); + CHECK(etl::u16string<20>(STR("127")) == etl::to_string(int8_t(INT8_MAX), str)); + CHECK(etl::u16string<20>(STR("32767")) == etl::to_string(int16_t(INT16_MAX), str)); + CHECK(etl::u16string<20>(STR("2147483647")) == etl::to_string(int32_t(INT32_MAX), str)); + CHECK(etl::u16string<20>(STR("9223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str)); - CHECK(etl::u16string<20>(STR("-128")) == etl::to_string(int8_t(-128), str)); - CHECK(etl::u16string<20>(STR("-32768")) == etl::to_string(int16_t(-32768), str)); - CHECK(etl::u16string<20>(STR("-2147483648")) == etl::to_string(int32_t(-2147483648ll), str)); - CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str)); + CHECK(etl::u16string<20>(STR("-128")) == etl::to_string(int8_t(INT8_MIN), str)); + CHECK(etl::u16string<20>(STR("-32768")) == etl::to_string(int16_t(INT16_MIN), str)); + CHECK(etl::u16string<20>(STR("-2147483648")) == etl::to_string(int32_t(INT32_MIN), str)); + CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str)); } //************************************************************************* @@ -72,7 +72,7 @@ namespace { etl::u16string<120> str; - CHECK(etl::u16string<120>(STR("0")) == etl::to_string(uint8_t(0), str, true)); + CHECK(etl::u16string<120>(STR("0")) == etl::to_string(uint8_t(0), str, true)); CHECK(etl::u16string<120>(STR("00")) == etl::to_string(uint16_t(0), str, true)); CHECK(etl::u16string<120>(STR("000")) == etl::to_string(uint32_t(0), str, true)); CHECK(etl::u16string<120>(STR("0000")) == etl::to_string(uint64_t(0), str, true)); @@ -82,15 +82,15 @@ namespace CHECK(etl::u16string<120>(STR("0000128327682147483648")) == etl::to_string(uint32_t(2147483648ul), str, true)); CHECK(etl::u16string<120>(STR("00001283276821474836489223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, true)); - CHECK(etl::u16string<120>(STR("00001283276821474836489223372036854775808127")) == etl::to_string(int8_t(127), str, true)); - CHECK(etl::u16string<120>(STR("0000128327682147483648922337203685477580812732767")) == etl::to_string(int16_t(32767), str, true)); - CHECK(etl::u16string<120>(STR("00001283276821474836489223372036854775808127327672147483647")) == etl::to_string(int32_t(2147483647ll), str, true)); - CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str, true)); + CHECK(etl::u16string<120>(STR("00001283276821474836489223372036854775808127")) == etl::to_string(int8_t(INT8_MAX), str, true)); + CHECK(etl::u16string<120>(STR("0000128327682147483648922337203685477580812732767")) == etl::to_string(int16_t(INT16_MAX), str, true)); + CHECK(etl::u16string<120>(STR("00001283276821474836489223372036854775808127327672147483647")) == etl::to_string(int32_t(INT32_MAX), str, true)); + CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str, true)); - CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")) == etl::to_string(int8_t(-128), str, true)); - CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")) == etl::to_string(int16_t(-32768), str, true)); - CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")) == etl::to_string(int32_t(-2147483648ll), str, true)); - CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, true)); + CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")) == etl::to_string(int8_t(INT8_MIN), str, true)); + CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")) == etl::to_string(int16_t(INT16_MIN), str, true)); + CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")) == etl::to_string(int32_t(INT32_MIN), str, true)); + CHECK(etl::u16string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, true)); } //************************************************************************* @@ -100,7 +100,7 @@ namespace Format format = Format().base(10).width(20).fill(STR('#')); - CHECK(etl::u16string<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format)); + CHECK(etl::u16string<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format)); CHECK(etl::u16string<20>(STR("###################0")) == etl::to_string(uint16_t(0), str, format)); CHECK(etl::u16string<20>(STR("###################0")) == etl::to_string(uint32_t(0), str, format)); CHECK(etl::u16string<20>(STR("###################0")) == etl::to_string(uint64_t(0), str, format)); @@ -110,15 +110,15 @@ namespace CHECK(etl::u16string<20>(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format)); CHECK(etl::u16string<20>(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format)); - CHECK(etl::u16string<20>(STR("#################127")) == etl::to_string(int8_t(127), str, format)); - CHECK(etl::u16string<20>(STR("###############32767")) == etl::to_string(int16_t(32767), str, format)); - CHECK(etl::u16string<20>(STR("##########2147483647")) == etl::to_string(int32_t(2147483647ll), str, format)); - CHECK(etl::u16string<20>(STR("#9223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str, format)); + CHECK(etl::u16string<20>(STR("#################127")) == etl::to_string(int8_t(INT8_MAX), str, format)); + CHECK(etl::u16string<20>(STR("###############32767")) == etl::to_string(int16_t(INT16_MAX), str, format)); + CHECK(etl::u16string<20>(STR("##########2147483647")) == etl::to_string(int32_t(INT32_MAX), str, format)); + CHECK(etl::u16string<20>(STR("#9223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str, format)); - CHECK(etl::u16string<20>(STR("################-128")) == etl::to_string(int8_t(-128), str, format)); - CHECK(etl::u16string<20>(STR("##############-32768")) == etl::to_string(int16_t(-32768), str, format)); - CHECK(etl::u16string<20>(STR("#########-2147483648")) == etl::to_string(int32_t(-2147483648ll), str, format)); - CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, format)); + CHECK(etl::u16string<20>(STR("################-128")) == etl::to_string(int8_t(INT8_MIN), str, format)); + CHECK(etl::u16string<20>(STR("##############-32768")) == etl::to_string(int16_t(INT16_MIN), str, format)); + CHECK(etl::u16string<20>(STR("#########-2147483648")) == etl::to_string(int32_t(INT32_MIN), str, format)); + CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, format)); } //************************************************************************* @@ -128,7 +128,7 @@ namespace Format format = Format().base(10).width(20).fill(STR('#')).left(); - CHECK(etl::u16string<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format)); + CHECK(etl::u16string<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format)); CHECK(etl::u16string<20>(STR("0###################")) == etl::to_string(uint16_t(0), str, format)); CHECK(etl::u16string<20>(STR("0###################")) == etl::to_string(uint32_t(0), str, format)); CHECK(etl::u16string<20>(STR("0###################")) == etl::to_string(uint64_t(0), str, format)); @@ -138,15 +138,15 @@ namespace CHECK(etl::u16string<20>(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format)); CHECK(etl::u16string<20>(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format)); - CHECK(etl::u16string<20>(STR("127#################")) == etl::to_string(int8_t(127), str, format)); - CHECK(etl::u16string<20>(STR("32767###############")) == etl::to_string(int16_t(32767), str, format)); - CHECK(etl::u16string<20>(STR("2147483647##########")) == etl::to_string(int32_t(2147483647ll), str, format)); - CHECK(etl::u16string<20>(STR("9223372036854775807#")) == etl::to_string(int64_t(9223372036854775807ll), str, format)); + CHECK(etl::u16string<20>(STR("127#################")) == etl::to_string(int8_t(INT8_MAX), str, format)); + CHECK(etl::u16string<20>(STR("32767###############")) == etl::to_string(int16_t(INT16_MAX), str, format)); + CHECK(etl::u16string<20>(STR("2147483647##########")) == etl::to_string(int32_t(INT32_MAX), str, format)); + CHECK(etl::u16string<20>(STR("9223372036854775807#")) == etl::to_string(int64_t(INT64_MAX), str, format)); - CHECK(etl::u16string<20>(STR("-128################")) == etl::to_string(int8_t(-128), str, format)); - CHECK(etl::u16string<20>(STR("-32768##############")) == etl::to_string(int16_t(-32768), str, format)); - CHECK(etl::u16string<20>(STR("-2147483648#########")) == etl::to_string(int32_t(-2147483648ll), str, format)); - CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, format)); + CHECK(etl::u16string<20>(STR("-128################")) == etl::to_string(int8_t(INT8_MIN), str, format)); + CHECK(etl::u16string<20>(STR("-32768##############")) == etl::to_string(int16_t(INT16_MIN), str, format)); + CHECK(etl::u16string<20>(STR("-2147483648#########")) == etl::to_string(int32_t(INT32_MIN), str, format)); + CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, format)); } //************************************************************************* @@ -154,7 +154,7 @@ namespace { etl::u16string<64> str; - CHECK(etl::u16string<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0')))); CHECK(etl::u16string<64>(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0')))); CHECK(etl::u16string<64>(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0')))); CHECK(etl::u16string<64>(STR("0000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0')))); @@ -164,15 +164,15 @@ namespace CHECK(etl::u16string<64>(STR("10000000000000000000000000000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0')))); CHECK(etl::u16string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(2).width(64).fill(STR('0')))); - CHECK(etl::u16string<64>(STR("01111111")) == etl::to_string(int8_t(127), str, Format().base(2).width(8).fill(STR('0')))); - CHECK(etl::u16string<64>(STR("0111111111111111")) == etl::to_string(int16_t(32767), str, Format().base(2).width(16).fill(STR('0')))); - CHECK(etl::u16string<64>(STR("01111111111111111111111111111111")) == etl::to_string(int32_t(2147483647ll), str, Format().base(2).width(32).fill(STR('0')))); - CHECK(etl::u16string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(2).width(64).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("01111111")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("0111111111111111")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(2).width(16).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("01111111111111111111111111111111")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(2).width(32).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(2).width(64).fill(STR('0')))); - CHECK(etl::u16string<64>(STR("10000000")) == etl::to_string(int8_t(-128), str, Format().base(2).width(8).fill(STR('0')))); - CHECK(etl::u16string<64>(STR("1000000000000000")) == etl::to_string(int16_t(-32768), str, Format().base(2).width(16).fill(STR('0')))); - CHECK(etl::u16string<64>(STR("10000000000000000000000000000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(2).width(32).fill(STR('0')))); - CHECK(etl::u16string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(2).width(64).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("10000000")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("1000000000000000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(2).width(16).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("10000000000000000000000000000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(2).width(32).fill(STR('0')))); + CHECK(etl::u16string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(2).width(64).fill(STR('0')))); } //************************************************************************* @@ -180,7 +180,7 @@ namespace { etl::u16string<22> str; - CHECK(etl::u16string<22>(STR("000")) == etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("000")) == etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0')))); CHECK(etl::u16string<22>(STR("000000")) == etl::to_string(uint16_t(0), str, Format().base(8).width(6).fill(STR('0')))); CHECK(etl::u16string<22>(STR("00000000000")) == etl::to_string(uint32_t(0), str, Format().base(8).width(11).fill(STR('0')))); CHECK(etl::u16string<22>(STR("0000000000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(8).width(22).fill(STR('0')))); @@ -190,15 +190,15 @@ namespace CHECK(etl::u16string<22>(STR("20000000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(8).width(11).fill(STR('0')))); CHECK(etl::u16string<22>(STR("1000000000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(8).width(22).fill(STR('0')))); - CHECK(etl::u16string<22>(STR("177")) == etl::to_string(int8_t(127), str, Format().base(8).width(3).fill(STR('0')))); - CHECK(etl::u16string<22>(STR("077777")) == etl::to_string(int16_t(32767), str, Format().base(8).width(6).fill(STR('0')))); - CHECK(etl::u16string<22>(STR("17777777777")) == etl::to_string(int32_t(2147483647ll), str, Format().base(8).width(11).fill(STR('0')))); - CHECK(etl::u16string<22>(STR("0777777777777777777777")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(8).width(22).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("177")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("077777")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(8).width(6).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("17777777777")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(8).width(11).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("0777777777777777777777")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(8).width(22).fill(STR('0')))); - CHECK(etl::u16string<22>(STR("200")) == etl::to_string(int8_t(-128), str, Format().base(8).width(3).fill(STR('0')))); - CHECK(etl::u16string<22>(STR("100000")) == etl::to_string(int16_t(-32768), str, Format().base(8).width(6).fill(STR('0')))); - CHECK(etl::u16string<22>(STR("20000000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(8).width(11).fill(STR('0')))); - CHECK(etl::u16string<22>(STR("1000000000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(8).width(22).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("200")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("100000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(8).width(6).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("20000000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(8).width(11).fill(STR('0')))); + CHECK(etl::u16string<22>(STR("1000000000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(8).width(22).fill(STR('0')))); } //************************************************************************* @@ -206,7 +206,7 @@ namespace { etl::u16string<16> str; - CHECK(etl::u16string<16>(STR("00")) == etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("00")) == etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0')))); CHECK(etl::u16string<16>(STR("0000")) == etl::to_string(uint16_t(0), str, Format().base(16).width(4).fill(STR('0')))); CHECK(etl::u16string<16>(STR("00000000")) == etl::to_string(uint32_t(0), str, Format().base(16).width(8).fill(STR('0')))); CHECK(etl::u16string<16>(STR("0000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(16).width(16).fill(STR('0')))); @@ -216,15 +216,15 @@ namespace CHECK(etl::u16string<16>(STR("80000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(16).width(8).fill(STR('0')))); CHECK(etl::u16string<16>(STR("8000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(16).width(16).fill(STR('0')))); - CHECK(etl::u16string<16>(STR("7f")) == etl::to_string(int8_t(127), str, Format().base(16).width(2).fill(STR('0')))); - CHECK(etl::u16string<16>(STR("7fff")) == etl::to_string(int16_t(32767), str, Format().base(16).width(4).fill(STR('0')))); - CHECK(etl::u16string<16>(STR("7fffffff")) == etl::to_string(int32_t(2147483647ll), str, Format().base(16).width(8).fill(STR('0')))); - CHECK(etl::u16string<16>(STR("7fffffffffffffff")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(16).width(16).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("7f")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("7fff")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(16).width(4).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("7fffffff")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(16).width(8).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("7fffffffffffffff")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(16).width(16).fill(STR('0')))); - CHECK(etl::u16string<16>(STR("80")) == etl::to_string(int8_t(-128), str, Format().base(16).width(2).fill(STR('0')))); - CHECK(etl::u16string<16>(STR("8000")) == etl::to_string(int16_t(-32768), str, Format().base(16).width(4).fill(STR('0')))); - CHECK(etl::u16string<16>(STR("80000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0')))); - CHECK(etl::u16string<16>(STR("8000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(16).width(16).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("80")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("8000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(16).width(4).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("80000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(16).width(8).fill(STR('0')))); + CHECK(etl::u16string<16>(STR("8000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(16).width(16).fill(STR('0')))); } //************************************************************************* @@ -377,7 +377,7 @@ namespace TEST(test_integer_denominator_huge_precision_64bit) { etl::u16string<20> result; - int64_t value = -9223372036854775808LL; + int64_t value = INT64_MIN; Format format = Format().precision(100); diff --git a/test/test_to_u32string.cpp b/test/test_to_u32string.cpp index e8ac328f..6d479857 100644 --- a/test/test_to_u32string.cpp +++ b/test/test_to_u32string.cpp @@ -58,15 +58,15 @@ namespace CHECK(etl::u32string<20>(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str)); CHECK(etl::u32string<20>(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str)); - CHECK(etl::u32string<20>(STR("127")) == etl::to_string(int8_t(127), str)); - CHECK(etl::u32string<20>(STR("32767")) == etl::to_string(int16_t(32767), str)); - CHECK(etl::u32string<20>(STR("2147483647")) == etl::to_string(int32_t(2147483647ll), str)); - CHECK(etl::u32string<20>(STR("9223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str)); + CHECK(etl::u32string<20>(STR("127")) == etl::to_string(int8_t(INT8_MAX), str)); + CHECK(etl::u32string<20>(STR("32767")) == etl::to_string(int16_t(INT16_MAX), str)); + CHECK(etl::u32string<20>(STR("2147483647")) == etl::to_string(int32_t(INT32_MAX), str)); + CHECK(etl::u32string<20>(STR("9223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str)); - CHECK(etl::u32string<20>(STR("-128")) == etl::to_string(int8_t(-128), str)); - CHECK(etl::u32string<20>(STR("-32768")) == etl::to_string(int16_t(-32768), str)); - CHECK(etl::u32string<20>(STR("-2147483648")) == etl::to_string(int32_t(-2147483648ll), str)); - CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str)); + CHECK(etl::u32string<20>(STR("-128")) == etl::to_string(int8_t(INT8_MIN), str)); + CHECK(etl::u32string<20>(STR("-32768")) == etl::to_string(int16_t(INT16_MIN), str)); + CHECK(etl::u32string<20>(STR("-2147483648")) == etl::to_string(int32_t(INT32_MIN), str)); + CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str)); } //************************************************************************* @@ -74,7 +74,7 @@ namespace { etl::u32string<120> str; - CHECK(etl::u32string<120>(STR("0")) == etl::to_string(uint8_t(0), str, true)); + CHECK(etl::u32string<120>(STR("0")) == etl::to_string(uint8_t(0), str, true)); CHECK(etl::u32string<120>(STR("00")) == etl::to_string(uint16_t(0), str, true)); CHECK(etl::u32string<120>(STR("000")) == etl::to_string(uint32_t(0), str, true)); CHECK(etl::u32string<120>(STR("0000")) == etl::to_string(uint64_t(0), str, true)); @@ -84,15 +84,15 @@ namespace CHECK(etl::u32string<120>(STR("0000128327682147483648")) == etl::to_string(uint32_t(2147483648ul), str, true)); CHECK(etl::u32string<120>(STR("00001283276821474836489223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, true)); - CHECK(etl::u32string<120>(STR("00001283276821474836489223372036854775808127")) == etl::to_string(int8_t(127), str, true)); - CHECK(etl::u32string<120>(STR("0000128327682147483648922337203685477580812732767")) == etl::to_string(int16_t(32767), str, true)); - CHECK(etl::u32string<120>(STR("00001283276821474836489223372036854775808127327672147483647")) == etl::to_string(int32_t(2147483647ll), str, true)); - CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str, true)); + CHECK(etl::u32string<120>(STR("00001283276821474836489223372036854775808127")) == etl::to_string(int8_t(INT8_MAX), str, true)); + CHECK(etl::u32string<120>(STR("0000128327682147483648922337203685477580812732767")) == etl::to_string(int16_t(INT16_MAX), str, true)); + CHECK(etl::u32string<120>(STR("00001283276821474836489223372036854775808127327672147483647")) == etl::to_string(int32_t(INT32_MAX), str, true)); + CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str, true)); - CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")) == etl::to_string(int8_t(-128), str, true)); - CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")) == etl::to_string(int16_t(-32768), str, true)); - CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")) == etl::to_string(int32_t(-2147483648ll), str, true)); - CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, true)); + CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")) == etl::to_string(int8_t(INT8_MIN), str, true)); + CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")) == etl::to_string(int16_t(INT16_MIN), str, true)); + CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")) == etl::to_string(int32_t(INT32_MIN), str, true)); + CHECK(etl::u32string<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, true)); } //************************************************************************* @@ -102,7 +102,7 @@ namespace Format format = Format().base(10).width(20).fill(STR('#')); - CHECK(etl::u32string<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format)); + CHECK(etl::u32string<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format)); CHECK(etl::u32string<20>(STR("###################0")) == etl::to_string(uint16_t(0), str, format)); CHECK(etl::u32string<20>(STR("###################0")) == etl::to_string(uint32_t(0), str, format)); CHECK(etl::u32string<20>(STR("###################0")) == etl::to_string(uint64_t(0), str, format)); @@ -112,15 +112,15 @@ namespace CHECK(etl::u32string<20>(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format)); CHECK(etl::u32string<20>(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format)); - CHECK(etl::u32string<20>(STR("#################127")) == etl::to_string(int8_t(127), str, format)); - CHECK(etl::u32string<20>(STR("###############32767")) == etl::to_string(int16_t(32767), str, format)); - CHECK(etl::u32string<20>(STR("##########2147483647")) == etl::to_string(int32_t(2147483647ll), str, format)); - CHECK(etl::u32string<20>(STR("#9223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str, format)); + CHECK(etl::u32string<20>(STR("#################127")) == etl::to_string(int8_t(INT8_MAX), str, format)); + CHECK(etl::u32string<20>(STR("###############32767")) == etl::to_string(int16_t(INT16_MAX), str, format)); + CHECK(etl::u32string<20>(STR("##########2147483647")) == etl::to_string(int32_t(INT32_MAX), str, format)); + CHECK(etl::u32string<20>(STR("#9223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str, format)); - CHECK(etl::u32string<20>(STR("################-128")) == etl::to_string(int8_t(-128), str, format)); - CHECK(etl::u32string<20>(STR("##############-32768")) == etl::to_string(int16_t(-32768), str, format)); - CHECK(etl::u32string<20>(STR("#########-2147483648")) == etl::to_string(int32_t(-2147483648ll), str, format)); - CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, format)); + CHECK(etl::u32string<20>(STR("################-128")) == etl::to_string(int8_t(INT8_MIN), str, format)); + CHECK(etl::u32string<20>(STR("##############-32768")) == etl::to_string(int16_t(INT16_MIN), str, format)); + CHECK(etl::u32string<20>(STR("#########-2147483648")) == etl::to_string(int32_t(INT32_MIN), str, format)); + CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, format)); } //************************************************************************* @@ -130,7 +130,7 @@ namespace Format format = Format().base(10).width(20).fill(STR('#')).left(); - CHECK(etl::u32string<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format)); + CHECK(etl::u32string<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format)); CHECK(etl::u32string<20>(STR("0###################")) == etl::to_string(uint16_t(0), str, format)); CHECK(etl::u32string<20>(STR("0###################")) == etl::to_string(uint32_t(0), str, format)); CHECK(etl::u32string<20>(STR("0###################")) == etl::to_string(uint64_t(0), str, format)); @@ -140,15 +140,15 @@ namespace CHECK(etl::u32string<20>(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format)); CHECK(etl::u32string<20>(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format)); - CHECK(etl::u32string<20>(STR("127#################")) == etl::to_string(int8_t(127), str, format)); - CHECK(etl::u32string<20>(STR("32767###############")) == etl::to_string(int16_t(32767), str, format)); - CHECK(etl::u32string<20>(STR("2147483647##########")) == etl::to_string(int32_t(2147483647ll), str, format)); - CHECK(etl::u32string<20>(STR("9223372036854775807#")) == etl::to_string(int64_t(9223372036854775807ll), str, format)); + CHECK(etl::u32string<20>(STR("127#################")) == etl::to_string(int8_t(INT8_MAX), str, format)); + CHECK(etl::u32string<20>(STR("32767###############")) == etl::to_string(int16_t(INT16_MAX), str, format)); + CHECK(etl::u32string<20>(STR("2147483647##########")) == etl::to_string(int32_t(INT32_MAX), str, format)); + CHECK(etl::u32string<20>(STR("9223372036854775807#")) == etl::to_string(int64_t(INT64_MAX), str, format)); - CHECK(etl::u32string<20>(STR("-128################")) == etl::to_string(int8_t(-128), str, format)); - CHECK(etl::u32string<20>(STR("-32768##############")) == etl::to_string(int16_t(-32768), str, format)); - CHECK(etl::u32string<20>(STR("-2147483648#########")) == etl::to_string(int32_t(-2147483648ll), str, format)); - CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, format)); + CHECK(etl::u32string<20>(STR("-128################")) == etl::to_string(int8_t(INT8_MIN), str, format)); + CHECK(etl::u32string<20>(STR("-32768##############")) == etl::to_string(int16_t(INT16_MIN), str, format)); + CHECK(etl::u32string<20>(STR("-2147483648#########")) == etl::to_string(int32_t(INT32_MIN), str, format)); + CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, format)); } //************************************************************************* @@ -156,7 +156,7 @@ namespace { etl::u32string<64> str; - CHECK(etl::u32string<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0')))); CHECK(etl::u32string<64>(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0')))); CHECK(etl::u32string<64>(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0')))); CHECK(etl::u32string<64>(STR("0000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0')))); @@ -166,15 +166,15 @@ namespace CHECK(etl::u32string<64>(STR("10000000000000000000000000000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0')))); CHECK(etl::u32string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(2).width(64).fill(STR('0')))); - CHECK(etl::u32string<64>(STR("01111111")) == etl::to_string(int8_t(127), str, Format().base(2).width(8).fill(STR('0')))); - CHECK(etl::u32string<64>(STR("0111111111111111")) == etl::to_string(int16_t(32767), str, Format().base(2).width(16).fill(STR('0')))); - CHECK(etl::u32string<64>(STR("01111111111111111111111111111111")) == etl::to_string(int32_t(2147483647ll), str, Format().base(2).width(32).fill(STR('0')))); - CHECK(etl::u32string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(2).width(64).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("01111111")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("0111111111111111")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(2).width(16).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("01111111111111111111111111111111")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(2).width(32).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(2).width(64).fill(STR('0')))); - CHECK(etl::u32string<64>(STR("10000000")) == etl::to_string(int8_t(-128), str, Format().base(2).width(8).fill(STR('0')))); - CHECK(etl::u32string<64>(STR("1000000000000000")) == etl::to_string(int16_t(-32768), str, Format().base(2).width(16).fill(STR('0')))); - CHECK(etl::u32string<64>(STR("10000000000000000000000000000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(2).width(32).fill(STR('0')))); - CHECK(etl::u32string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(2).width(64).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("10000000")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("1000000000000000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(2).width(16).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("10000000000000000000000000000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(2).width(32).fill(STR('0')))); + CHECK(etl::u32string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(2).width(64).fill(STR('0')))); } //************************************************************************* @@ -182,7 +182,7 @@ namespace { etl::u32string<22> str; - CHECK(etl::u32string<22>(STR("000")) == etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("000")) == etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0')))); CHECK(etl::u32string<22>(STR("000000")) == etl::to_string(uint16_t(0), str, Format().base(8).width(6).fill(STR('0')))); CHECK(etl::u32string<22>(STR("00000000000")) == etl::to_string(uint32_t(0), str, Format().base(8).width(11).fill(STR('0')))); CHECK(etl::u32string<22>(STR("0000000000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(8).width(22).fill(STR('0')))); @@ -192,15 +192,15 @@ namespace CHECK(etl::u32string<22>(STR("20000000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(8).width(11).fill(STR('0')))); CHECK(etl::u32string<22>(STR("1000000000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(8).width(22).fill(STR('0')))); - CHECK(etl::u32string<22>(STR("177")) == etl::to_string(int8_t(127), str, Format().base(8).width(3).fill(STR('0')))); - CHECK(etl::u32string<22>(STR("077777")) == etl::to_string(int16_t(32767), str, Format().base(8).width(6).fill(STR('0')))); - CHECK(etl::u32string<22>(STR("17777777777")) == etl::to_string(int32_t(2147483647ll), str, Format().base(8).width(11).fill(STR('0')))); - CHECK(etl::u32string<22>(STR("0777777777777777777777")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(8).width(22).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("177")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("077777")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(8).width(6).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("17777777777")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(8).width(11).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("0777777777777777777777")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(8).width(22).fill(STR('0')))); - CHECK(etl::u32string<22>(STR("200")) == etl::to_string(int8_t(-128), str, Format().base(8).width(3).fill(STR('0')))); - CHECK(etl::u32string<22>(STR("100000")) == etl::to_string(int16_t(-32768), str, Format().base(8).width(6).fill(STR('0')))); - CHECK(etl::u32string<22>(STR("20000000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(8).width(11).fill(STR('0')))); - CHECK(etl::u32string<22>(STR("1000000000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(8).width(22).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("200")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("100000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(8).width(6).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("20000000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(8).width(11).fill(STR('0')))); + CHECK(etl::u32string<22>(STR("1000000000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(8).width(22).fill(STR('0')))); } //************************************************************************* @@ -208,7 +208,7 @@ namespace { etl::u32string<16> str; - CHECK(etl::u32string<16>(STR("00")) == etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("00")) == etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0')))); CHECK(etl::u32string<16>(STR("0000")) == etl::to_string(uint16_t(0), str, Format().base(16).width(4).fill(STR('0')))); CHECK(etl::u32string<16>(STR("00000000")) == etl::to_string(uint32_t(0), str, Format().base(16).width(8).fill(STR('0')))); CHECK(etl::u32string<16>(STR("0000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(16).width(16).fill(STR('0')))); @@ -218,15 +218,15 @@ namespace CHECK(etl::u32string<16>(STR("80000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(16).width(8).fill(STR('0')))); CHECK(etl::u32string<16>(STR("8000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(16).width(16).fill(STR('0')))); - CHECK(etl::u32string<16>(STR("7f")) == etl::to_string(int8_t(127), str, Format().base(16).width(2).fill(STR('0')))); - CHECK(etl::u32string<16>(STR("7fff")) == etl::to_string(int16_t(32767), str, Format().base(16).width(4).fill(STR('0')))); - CHECK(etl::u32string<16>(STR("7fffffff")) == etl::to_string(int32_t(2147483647ll), str, Format().base(16).width(8).fill(STR('0')))); - CHECK(etl::u32string<16>(STR("7fffffffffffffff")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(16).width(16).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("7f")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("7fff")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(16).width(4).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("7fffffff")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(16).width(8).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("7fffffffffffffff")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(16).width(16).fill(STR('0')))); - CHECK(etl::u32string<16>(STR("80")) == etl::to_string(int8_t(-128), str, Format().base(16).width(2).fill(STR('0')))); - CHECK(etl::u32string<16>(STR("8000")) == etl::to_string(int16_t(-32768), str, Format().base(16).width(4).fill(STR('0')))); - CHECK(etl::u32string<16>(STR("80000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0')))); - CHECK(etl::u32string<16>(STR("8000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(16).width(16).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("80")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("8000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(16).width(4).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("80000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(16).width(8).fill(STR('0')))); + CHECK(etl::u32string<16>(STR("8000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(16).width(16).fill(STR('0')))); } @@ -382,7 +382,7 @@ namespace TEST(test_integer_denominator_huge_precision_64bit) { etl::u32string<20> result; - int64_t value = -9223372036854775808LL; + int64_t value = INT64_MIN; Format format = Format().precision(100); diff --git a/test/test_to_wstring.cpp b/test/test_to_wstring.cpp index 35ecf78e..88c2dd46 100644 --- a/test/test_to_wstring.cpp +++ b/test/test_to_wstring.cpp @@ -60,15 +60,15 @@ namespace CHECK(etl::wstring<20>(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str)); CHECK(etl::wstring<20>(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str)); - CHECK(etl::wstring<20>(STR("127")) == etl::to_string(int8_t(127), str)); - CHECK(etl::wstring<20>(STR("32767")) == etl::to_string(int16_t(32767), str)); - CHECK(etl::wstring<20>(STR("2147483647")) == etl::to_string(int32_t(2147483647ll), str)); - CHECK(etl::wstring<20>(STR("9223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str)); + CHECK(etl::wstring<20>(STR("127")) == etl::to_string(int8_t(INT8_MAX), str)); + CHECK(etl::wstring<20>(STR("32767")) == etl::to_string(int16_t(INT16_MAX), str)); + CHECK(etl::wstring<20>(STR("2147483647")) == etl::to_string(int32_t(INT32_MAX), str)); + CHECK(etl::wstring<20>(STR("9223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str)); - CHECK(etl::wstring<20>(STR("-128")) == etl::to_string(int8_t(-128), str)); - CHECK(etl::wstring<20>(STR("-32768")) == etl::to_string(int16_t(-32768), str)); - CHECK(etl::wstring<20>(STR("-2147483648")) == etl::to_string(int32_t(-2147483648ll), str)); - CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str)); + CHECK(etl::wstring<20>(STR("-128")) == etl::to_string(int8_t(INT8_MIN), str)); + CHECK(etl::wstring<20>(STR("-32768")) == etl::to_string(int16_t(INT16_MIN), str)); + CHECK(etl::wstring<20>(STR("-2147483648")) == etl::to_string(int32_t(INT32_MIN), str)); + CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str)); } //************************************************************************* @@ -76,7 +76,7 @@ namespace { etl::wstring<120> str; - CHECK(etl::wstring<120>(STR("0")) == etl::to_string(uint8_t(0), str, true)); + CHECK(etl::wstring<120>(STR("0")) == etl::to_string(uint8_t(0), str, true)); CHECK(etl::wstring<120>(STR("00")) == etl::to_string(uint16_t(0), str, true)); CHECK(etl::wstring<120>(STR("000")) == etl::to_string(uint32_t(0), str, true)); CHECK(etl::wstring<120>(STR("0000")) == etl::to_string(uint64_t(0), str, true)); @@ -86,15 +86,15 @@ namespace CHECK(etl::wstring<120>(STR("0000128327682147483648")) == etl::to_string(uint32_t(2147483648ul), str, true)); CHECK(etl::wstring<120>(STR("00001283276821474836489223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, true)); - CHECK(etl::wstring<120>(STR("00001283276821474836489223372036854775808127")) == etl::to_string(int8_t(127), str, true)); - CHECK(etl::wstring<120>(STR("0000128327682147483648922337203685477580812732767")) == etl::to_string(int16_t(32767), str, true)); - CHECK(etl::wstring<120>(STR("00001283276821474836489223372036854775808127327672147483647")) == etl::to_string(int32_t(2147483647ll), str, true)); - CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str, true)); + CHECK(etl::wstring<120>(STR("00001283276821474836489223372036854775808127")) == etl::to_string(int8_t(INT8_MAX), str, true)); + CHECK(etl::wstring<120>(STR("0000128327682147483648922337203685477580812732767")) == etl::to_string(int16_t(INT16_MAX), str, true)); + CHECK(etl::wstring<120>(STR("00001283276821474836489223372036854775808127327672147483647")) == etl::to_string(int32_t(INT32_MAX), str, true)); + CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str, true)); - CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")) == etl::to_string(int8_t(-128), str, true)); - CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")) == etl::to_string(int16_t(-32768), str, true)); - CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")) == etl::to_string(int32_t(-2147483648ll), str, true)); - CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, true)); + CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128")) == etl::to_string(int8_t(INT8_MIN), str, true)); + CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768")) == etl::to_string(int16_t(INT16_MIN), str, true)); + CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648")) == etl::to_string(int32_t(INT32_MIN), str, true)); + CHECK(etl::wstring<120>(STR("000012832768214748364892233720368547758081273276721474836479223372036854775807-128-32768-2147483648-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, true)); } //************************************************************************* @@ -104,7 +104,7 @@ namespace Format format = Format().base(10).width(20).fill(STR('#')); - CHECK(etl::wstring<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format)); + CHECK(etl::wstring<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format)); CHECK(etl::wstring<20>(STR("###################0")) == etl::to_string(uint16_t(0), str, format)); CHECK(etl::wstring<20>(STR("###################0")) == etl::to_string(uint32_t(0), str, format)); CHECK(etl::wstring<20>(STR("###################0")) == etl::to_string(uint64_t(0), str, format)); @@ -114,15 +114,15 @@ namespace CHECK(etl::wstring<20>(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format)); CHECK(etl::wstring<20>(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format)); - CHECK(etl::wstring<20>(STR("#################127")) == etl::to_string(int8_t(127), str, format)); - CHECK(etl::wstring<20>(STR("###############32767")) == etl::to_string(int16_t(32767), str, format)); - CHECK(etl::wstring<20>(STR("##########2147483647")) == etl::to_string(int32_t(2147483647ll), str, format)); - CHECK(etl::wstring<20>(STR("#9223372036854775807")) == etl::to_string(int64_t(9223372036854775807ll), str, format)); + CHECK(etl::wstring<20>(STR("#################127")) == etl::to_string(int8_t(INT8_MAX), str, format)); + CHECK(etl::wstring<20>(STR("###############32767")) == etl::to_string(int16_t(INT16_MAX), str, format)); + CHECK(etl::wstring<20>(STR("##########2147483647")) == etl::to_string(int32_t(INT32_MAX), str, format)); + CHECK(etl::wstring<20>(STR("#9223372036854775807")) == etl::to_string(int64_t(INT64_MAX), str, format)); - CHECK(etl::wstring<20>(STR("################-128")) == etl::to_string(int8_t(-128), str, format)); - CHECK(etl::wstring<20>(STR("##############-32768")) == etl::to_string(int16_t(-32768), str, format)); - CHECK(etl::wstring<20>(STR("#########-2147483648")) == etl::to_string(int32_t(-2147483648ll), str, format)); - CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, format)); + CHECK(etl::wstring<20>(STR("################-128")) == etl::to_string(int8_t(INT8_MIN), str, format)); + CHECK(etl::wstring<20>(STR("##############-32768")) == etl::to_string(int16_t(INT16_MIN), str, format)); + CHECK(etl::wstring<20>(STR("#########-2147483648")) == etl::to_string(int32_t(INT32_MIN), str, format)); + CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, format)); } //************************************************************************* @@ -132,7 +132,7 @@ namespace Format format = Format().base(10).width(20).fill(STR('#')).left(); - CHECK(etl::wstring<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format)); + CHECK(etl::wstring<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format)); CHECK(etl::wstring<20>(STR("0###################")) == etl::to_string(uint16_t(0), str, format)); CHECK(etl::wstring<20>(STR("0###################")) == etl::to_string(uint32_t(0), str, format)); CHECK(etl::wstring<20>(STR("0###################")) == etl::to_string(uint64_t(0), str, format)); @@ -142,15 +142,15 @@ namespace CHECK(etl::wstring<20>(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format)); CHECK(etl::wstring<20>(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format)); - CHECK(etl::wstring<20>(STR("127#################")) == etl::to_string(int8_t(127), str, format)); - CHECK(etl::wstring<20>(STR("32767###############")) == etl::to_string(int16_t(32767), str, format)); - CHECK(etl::wstring<20>(STR("2147483647##########")) == etl::to_string(int32_t(2147483647ll), str, format)); - CHECK(etl::wstring<20>(STR("9223372036854775807#")) == etl::to_string(int64_t(9223372036854775807ll), str, format)); + CHECK(etl::wstring<20>(STR("127#################")) == etl::to_string(int8_t(INT8_MAX), str, format)); + CHECK(etl::wstring<20>(STR("32767###############")) == etl::to_string(int16_t(INT16_MAX), str, format)); + CHECK(etl::wstring<20>(STR("2147483647##########")) == etl::to_string(int32_t(INT32_MAX), str, format)); + CHECK(etl::wstring<20>(STR("9223372036854775807#")) == etl::to_string(int64_t(INT64_MAX), str, format)); - CHECK(etl::wstring<20>(STR("-128################")) == etl::to_string(int8_t(-128), str, format)); - CHECK(etl::wstring<20>(STR("-32768##############")) == etl::to_string(int16_t(-32768), str, format)); - CHECK(etl::wstring<20>(STR("-2147483648#########")) == etl::to_string(int32_t(-2147483648ll), str, format)); - CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, format)); + CHECK(etl::wstring<20>(STR("-128################")) == etl::to_string(int8_t(INT8_MIN), str, format)); + CHECK(etl::wstring<20>(STR("-32768##############")) == etl::to_string(int16_t(INT16_MIN), str, format)); + CHECK(etl::wstring<20>(STR("-2147483648#########")) == etl::to_string(int32_t(INT32_MIN), str, format)); + CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(int64_t(INT64_MIN), str, format)); } //************************************************************************* @@ -158,7 +158,7 @@ namespace { etl::wstring<64> str; - CHECK(etl::wstring<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0')))); CHECK(etl::wstring<64>(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0')))); CHECK(etl::wstring<64>(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0')))); CHECK(etl::wstring<64>(STR("0000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0')))); @@ -168,15 +168,15 @@ namespace CHECK(etl::wstring<64>(STR("10000000000000000000000000000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0')))); CHECK(etl::wstring<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(2).width(64).fill(STR('0')))); - CHECK(etl::wstring<64>(STR("01111111")) == etl::to_string(int8_t(127), str, Format().base(2).width(8).fill(STR('0')))); - CHECK(etl::wstring<64>(STR("0111111111111111")) == etl::to_string(int16_t(32767), str, Format().base(2).width(16).fill(STR('0')))); - CHECK(etl::wstring<64>(STR("01111111111111111111111111111111")) == etl::to_string(int32_t(2147483647ll), str, Format().base(2).width(32).fill(STR('0')))); - CHECK(etl::wstring<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(2).width(64).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("01111111")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("0111111111111111")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(2).width(16).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("01111111111111111111111111111111")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(2).width(32).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("0111111111111111111111111111111111111111111111111111111111111111")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(2).width(64).fill(STR('0')))); - CHECK(etl::wstring<64>(STR("10000000")) == etl::to_string(int8_t(-128), str, Format().base(2).width(8).fill(STR('0')))); - CHECK(etl::wstring<64>(STR("1000000000000000")) == etl::to_string(int16_t(-32768), str, Format().base(2).width(16).fill(STR('0')))); - CHECK(etl::wstring<64>(STR("10000000000000000000000000000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(2).width(32).fill(STR('0')))); - CHECK(etl::wstring<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(2).width(64).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("10000000")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(2).width(8).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("1000000000000000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(2).width(16).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("10000000000000000000000000000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(2).width(32).fill(STR('0')))); + CHECK(etl::wstring<64>(STR("1000000000000000000000000000000000000000000000000000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(2).width(64).fill(STR('0')))); } //************************************************************************* @@ -184,7 +184,7 @@ namespace { etl::wstring<22> str; - CHECK(etl::wstring<22>(STR("000")) == etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("000")) == etl::to_string(uint8_t(0), str, Format().base(8).width(3).fill(STR('0')))); CHECK(etl::wstring<22>(STR("000000")) == etl::to_string(uint16_t(0), str, Format().base(8).width(6).fill(STR('0')))); CHECK(etl::wstring<22>(STR("00000000000")) == etl::to_string(uint32_t(0), str, Format().base(8).width(11).fill(STR('0')))); CHECK(etl::wstring<22>(STR("0000000000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(8).width(22).fill(STR('0')))); @@ -194,15 +194,15 @@ namespace CHECK(etl::wstring<22>(STR("20000000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(8).width(11).fill(STR('0')))); CHECK(etl::wstring<22>(STR("1000000000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(8).width(22).fill(STR('0')))); - CHECK(etl::wstring<22>(STR("177")) == etl::to_string(int8_t(127), str, Format().base(8).width(3).fill(STR('0')))); - CHECK(etl::wstring<22>(STR("077777")) == etl::to_string(int16_t(32767), str, Format().base(8).width(6).fill(STR('0')))); - CHECK(etl::wstring<22>(STR("17777777777")) == etl::to_string(int32_t(2147483647ll), str, Format().base(8).width(11).fill(STR('0')))); - CHECK(etl::wstring<22>(STR("0777777777777777777777")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(8).width(22).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("177")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("077777")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(8).width(6).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("17777777777")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(8).width(11).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("0777777777777777777777")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(8).width(22).fill(STR('0')))); - CHECK(etl::wstring<22>(STR("200")) == etl::to_string(int8_t(-128), str, Format().base(8).width(3).fill(STR('0')))); - CHECK(etl::wstring<22>(STR("100000")) == etl::to_string(int16_t(-32768), str, Format().base(8).width(6).fill(STR('0')))); - CHECK(etl::wstring<22>(STR("20000000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(8).width(11).fill(STR('0')))); - CHECK(etl::wstring<22>(STR("1000000000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(8).width(22).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("200")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(8).width(3).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("100000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(8).width(6).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("20000000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(8).width(11).fill(STR('0')))); + CHECK(etl::wstring<22>(STR("1000000000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(8).width(22).fill(STR('0')))); } //************************************************************************* @@ -210,7 +210,7 @@ namespace { etl::wstring<16> str; - CHECK(etl::wstring<16>(STR("00")) == etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("00")) == etl::to_string(uint8_t(0), str, Format().base(16).width(2).fill(STR('0')))); CHECK(etl::wstring<16>(STR("0000")) == etl::to_string(uint16_t(0), str, Format().base(16).width(4).fill(STR('0')))); CHECK(etl::wstring<16>(STR("00000000")) == etl::to_string(uint32_t(0), str, Format().base(16).width(8).fill(STR('0')))); CHECK(etl::wstring<16>(STR("0000000000000000")) == etl::to_string(uint64_t(0), str, Format().base(16).width(16).fill(STR('0')))); @@ -220,15 +220,15 @@ namespace CHECK(etl::wstring<16>(STR("80000000")) == etl::to_string(uint32_t(2147483648ul), str, Format().base(16).width(8).fill(STR('0')))); CHECK(etl::wstring<16>(STR("8000000000000000")) == etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(16).width(16).fill(STR('0')))); - CHECK(etl::wstring<16>(STR("7f")) == etl::to_string(int8_t(127), str, Format().base(16).width(2).fill(STR('0')))); - CHECK(etl::wstring<16>(STR("7fff")) == etl::to_string(int16_t(32767), str, Format().base(16).width(4).fill(STR('0')))); - CHECK(etl::wstring<16>(STR("7fffffff")) == etl::to_string(int32_t(2147483647ll), str, Format().base(16).width(8).fill(STR('0')))); - CHECK(etl::wstring<16>(STR("7fffffffffffffff")) == etl::to_string(int64_t(9223372036854775807ll), str, Format().base(16).width(16).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("7f")) == etl::to_string(int8_t(INT8_MAX), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("7fff")) == etl::to_string(int16_t(INT16_MAX), str, Format().base(16).width(4).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("7fffffff")) == etl::to_string(int32_t(INT32_MAX), str, Format().base(16).width(8).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("7fffffffffffffff")) == etl::to_string(int64_t(INT64_MAX), str, Format().base(16).width(16).fill(STR('0')))); - CHECK(etl::wstring<16>(STR("80")) == etl::to_string(int8_t(-128), str, Format().base(16).width(2).fill(STR('0')))); - CHECK(etl::wstring<16>(STR("8000")) == etl::to_string(int16_t(-32768), str, Format().base(16).width(4).fill(STR('0')))); - CHECK(etl::wstring<16>(STR("80000000")) == etl::to_string(int32_t(-2147483648ll), str, Format().base(16).width(8).fill(STR('0')))); - CHECK(etl::wstring<16>(STR("8000000000000000")) == etl::to_string(int64_t(-9223372036854775807ll - 1), str, Format().base(16).width(16).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("80")) == etl::to_string(int8_t(INT8_MIN), str, Format().base(16).width(2).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("8000")) == etl::to_string(int16_t(INT16_MIN), str, Format().base(16).width(4).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("80000000")) == etl::to_string(int32_t(INT32_MIN), str, Format().base(16).width(8).fill(STR('0')))); + CHECK(etl::wstring<16>(STR("8000000000000000")) == etl::to_string(int64_t(INT64_MIN), str, Format().base(16).width(16).fill(STR('0')))); } //************************************************************************* @@ -444,7 +444,7 @@ namespace TEST(test_integer_denominator_huge_precision_64bit) { etl::wstring<20> result; - int64_t value = -9223372036854775808LL; + int64_t value = INT64_MIN; Format format = Format().precision(100);