mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Feature/to string float uses double math (#1610)
* Added overloaded etl::floor() and etl::ceil() Added tests for float, double, long double * Documented functions from math.h * Added more math wrappers. Move wrappers to clib namespace * Cleanup of duplicated code. * clang-format * Code review updates --------- Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
This commit is contained in:
parent
a8ab0bbeea
commit
88c1b34411
306
docs/maths/math.md
Normal file
306
docs/maths/math.md
Normal file
@ -0,0 +1,306 @@
|
||||
---
|
||||
title: "math"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `math.h`
|
||||
From: `20.50.0`
|
||||
{{< /callout >}}
|
||||
|
||||
Various mathematical utilities
|
||||
|
||||
## is_nan
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_nan(T value)
|
||||
```
|
||||
**Returns**
|
||||
`true` if `value` is `NAN` (Not A Number).
|
||||
Always returns `false` if `T` is an integral.
|
||||
|
||||
## is_infinity
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_infinity(T value)
|
||||
```
|
||||
**Returns**
|
||||
`true` if `value` is infinity.
|
||||
Always returns `false` if `T` is an integral.
|
||||
|
||||
## is_zero
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_zero(T value)
|
||||
```
|
||||
**Returns**
|
||||
`true` if `value` is Zero.
|
||||
|
||||
## is_exactly_zero
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_exactly_equal(T value1, T value2)
|
||||
```
|
||||
**Returns**
|
||||
`true` if `value1` is equal to `value2`.
|
||||
|
||||
## floor
|
||||
|
||||
Defined in the `etl::math` namespace.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
float floor(float value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::floorf` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::floorf(value)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
double floor(double value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::floor` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::floor(value)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
long double floor(long double value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::floorl` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
|
||||
`::floor` with casts to `double`.
|
||||
otherwise
|
||||
`::floorl(value)`
|
||||
|
||||
## ceil
|
||||
|
||||
Defined in the `etl::math` namespace.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
float ceil(float value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::ceilf` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::ceilf(value)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
double ceil(double value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::ceil` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::ceil(value)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
long double ceil(long double value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::ceill` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
|
||||
`::ceil` with casts to `double`.
|
||||
otherwise
|
||||
`::ceill(value)`
|
||||
|
||||
## log10
|
||||
|
||||
Defined in the `etl::math` namespace.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
float log10(float value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::log10f` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::log10f(value)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
double log10(double value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::log10` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::log10(value)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
long double log10(long double value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::log10l` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
|
||||
`::log10` with casts to `double`.
|
||||
otherwise
|
||||
`::log10l(value)`
|
||||
|
||||
## round
|
||||
|
||||
Defined in the `etl::math` namespace.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
float round(float value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::roundf` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::roundf(value)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
double round(double value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::round` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::round(value)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
long double round(long double value) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::roundl` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
|
||||
`::round` with casts to `double`.
|
||||
otherwise
|
||||
`::roundl(value)`
|
||||
|
||||
## pow
|
||||
|
||||
Defined in the `etl::math` namespace.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
float pow(float base, float exponent) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::powf` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::powf(base, exponent)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
double pow(double base, double exponent) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::pow` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::pow(base, exponent)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
long double pow(long double base, long double exponent) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::powl` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
|
||||
`::pow` with casts to `double`.
|
||||
otherwise
|
||||
`::powl(base, intpart)`
|
||||
|
||||
## modf
|
||||
|
||||
Defined in the `etl::math` namespace.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
float modf(float value, float* intpart) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::modff` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::modff(value, intpart)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
double modf(double value, double* intpart) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::modf` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
`::modf(value, intpart)`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
long double modf(long double value, long double* intpart) ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
A wrapper around `::modfl` in `<math.h>`.
|
||||
|
||||
**Returns**
|
||||
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
|
||||
`::modf` with casts to `double`.
|
||||
otherwise
|
||||
`::modfl(value, intpart)`
|
||||
@ -47,10 +47,6 @@ SOFTWARE.
|
||||
#include "variant.h"
|
||||
#include "visitor.h"
|
||||
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
#include <cmath>
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
|
||||
namespace etl
|
||||
@ -1751,65 +1747,6 @@ namespace etl
|
||||
double, long double>
|
||||
long_double_format_type;
|
||||
|
||||
#if ETL_NOT_USING_FORMAT_LONG_DOUBLE_MATH
|
||||
//***********************************
|
||||
// Math function wrappers to handle toolchains that don't provide
|
||||
// long double math functions (log10l, floorl, powl, modfl, roundl).
|
||||
// When ETL_FORMAT_NO_LONG_DOUBLE_MATH is defined, long double overloads
|
||||
// cast through double. For float and double, the standard functions are
|
||||
// called directly via the template versions.
|
||||
//***********************************
|
||||
inline long double format_log10(long double value)
|
||||
{
|
||||
return static_cast<long double>(::log10(static_cast<double>(value)));
|
||||
}
|
||||
inline long double format_floor(long double value)
|
||||
{
|
||||
return static_cast<long double>(::floor(static_cast<double>(value)));
|
||||
}
|
||||
inline long double format_pow(long double base, long double exp)
|
||||
{
|
||||
return static_cast<long double>(::pow(static_cast<double>(base), static_cast<double>(exp)));
|
||||
}
|
||||
inline long double format_round(long double value)
|
||||
{
|
||||
return static_cast<long double>(::round(static_cast<double>(value)));
|
||||
}
|
||||
inline long double format_modf(long double value, long double* iptr)
|
||||
{
|
||||
double d_iptr;
|
||||
double result = ::modf(static_cast<double>(value), &d_iptr);
|
||||
*iptr = static_cast<long double>(d_iptr);
|
||||
return static_cast<long double>(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
T format_log10(T value)
|
||||
{
|
||||
return ::log10(value);
|
||||
}
|
||||
template <typename T>
|
||||
T format_floor(T value)
|
||||
{
|
||||
return ::floor(value);
|
||||
}
|
||||
template <typename T>
|
||||
T format_pow(T base, T exp)
|
||||
{
|
||||
return ::pow(base, exp);
|
||||
}
|
||||
template <typename T>
|
||||
T format_round(T value)
|
||||
{
|
||||
return ::round(value);
|
||||
}
|
||||
template <typename T>
|
||||
T format_modf(T value, T* iptr)
|
||||
{
|
||||
return ::modf(value, iptr);
|
||||
}
|
||||
|
||||
template <typename OutputIt, typename T>
|
||||
void format_floating_default(OutputIt& it, T value, const format_spec_t& spec)
|
||||
{
|
||||
@ -1830,7 +1767,7 @@ namespace etl
|
||||
}
|
||||
|
||||
T integral;
|
||||
T fractional = format_modf(value, &integral);
|
||||
T fractional = etl::math::modf(value, &integral);
|
||||
|
||||
// Take absolute values to avoid casting negative values to unsigned
|
||||
if (sign)
|
||||
@ -1840,7 +1777,7 @@ namespace etl
|
||||
}
|
||||
|
||||
unsigned long long int scale = int_pow<unsigned long long int>(10, fractional_decimals);
|
||||
unsigned long long int fractional_int = static_cast<unsigned long long int>(format_round(fractional * scale));
|
||||
unsigned long long int fractional_int = static_cast<unsigned long long int>(etl::math::round(fractional * scale));
|
||||
unsigned long long int integral_int = static_cast<unsigned long long int>(integral);
|
||||
|
||||
if (fractional_int == scale)
|
||||
@ -1867,20 +1804,20 @@ namespace etl
|
||||
bool sign = signbit(value);
|
||||
|
||||
T integral;
|
||||
T fractional = format_modf(value, &integral);
|
||||
T fractional = etl::math::modf(value, &integral);
|
||||
|
||||
while (value >= 0x10 || value <= -0x10)
|
||||
{
|
||||
++exponent_int;
|
||||
value /= 0x10;
|
||||
fractional = format_modf(value, &integral);
|
||||
fractional = etl::math::modf(value, &integral);
|
||||
}
|
||||
|
||||
while ((value > 0.0000000000001 && value < 1) || (value < -0.0000000000001 && value > -1))
|
||||
{
|
||||
--exponent_int;
|
||||
value *= 0x10;
|
||||
fractional = format_modf(value, &integral);
|
||||
fractional = etl::math::modf(value, &integral);
|
||||
}
|
||||
|
||||
// Take absolute values to avoid casting negative values to unsigned
|
||||
@ -1891,7 +1828,7 @@ namespace etl
|
||||
}
|
||||
|
||||
unsigned long long int scale = int_pow<unsigned long long int>(0x10, fractional_decimals);
|
||||
unsigned long long int fractional_int = static_cast<unsigned long long int>(format_round(fractional * scale));
|
||||
unsigned long long int fractional_int = static_cast<unsigned long long int>(etl::math::round(fractional * scale));
|
||||
unsigned long long int integral_int = static_cast<unsigned long long int>(integral);
|
||||
|
||||
if (fractional_int == scale)
|
||||
@ -1935,8 +1872,8 @@ namespace etl
|
||||
|
||||
if (abs_value > static_cast<T>(0))
|
||||
{
|
||||
exponent_int = static_cast<long long int>(format_floor(format_log10(abs_value)));
|
||||
value = abs_value / format_pow(static_cast<T>(10), static_cast<T>(exponent_int));
|
||||
exponent_int = static_cast<long long int>(etl::math::floor(etl::math::log10(abs_value)));
|
||||
value = abs_value / etl::math::pow(static_cast<T>(10), static_cast<T>(exponent_int));
|
||||
// Correct for floating-point rounding in log10/pow
|
||||
if (value >= static_cast<T>(10))
|
||||
{
|
||||
@ -1955,10 +1892,10 @@ namespace etl
|
||||
}
|
||||
|
||||
T integral;
|
||||
T fractional = format_modf(value, &integral);
|
||||
T fractional = etl::math::modf(value, &integral);
|
||||
|
||||
unsigned long long int scale = int_pow<unsigned long long int>(10, fractional_decimals);
|
||||
unsigned long long int fractional_int = static_cast<unsigned long long int>(format_round(fractional * scale));
|
||||
unsigned long long int fractional_int = static_cast<unsigned long long int>(etl::math::round(fractional * scale));
|
||||
unsigned long long int integral_int = static_cast<unsigned long long int>(integral);
|
||||
|
||||
if (fractional_int == scale)
|
||||
@ -1996,7 +1933,7 @@ namespace etl
|
||||
bool sign = signbit(value);
|
||||
|
||||
T integral;
|
||||
T fractional = format_modf(value, &integral);
|
||||
T fractional = etl::math::modf(value, &integral);
|
||||
|
||||
// Take absolute values to avoid casting negative values to unsigned
|
||||
if (sign)
|
||||
@ -2006,7 +1943,7 @@ namespace etl
|
||||
}
|
||||
|
||||
unsigned long long int scale = int_pow<unsigned long long int>(10, fractional_decimals);
|
||||
unsigned long long int fractional_int = static_cast<unsigned long long int>(format_round(fractional * scale));
|
||||
unsigned long long int fractional_int = static_cast<unsigned long long int>(etl::math::round(fractional * scale));
|
||||
unsigned long long int integral_int = static_cast<unsigned long long int>(integral);
|
||||
|
||||
if (fractional_int == scale)
|
||||
|
||||
@ -131,6 +131,209 @@ namespace etl
|
||||
return value1 == value2;
|
||||
}
|
||||
#include "private/diagnostic_pop.h"
|
||||
|
||||
//***************************************************************************
|
||||
// These functions wrap the C math.h functions.
|
||||
// The functions are overloaded for the different floating point types.
|
||||
// They provide a consistent interface for float, double and long double.
|
||||
// They are in the `math` namespace to avoid conflicts with the C library and ETL functions.
|
||||
// These take the place of std::floor, std::ceil etc which may not be available `No STL` environments.
|
||||
// Avoids unpredictable behaviour for global calls of ::floor, ::ceil etc when both <math.h> and <cmath> are included.
|
||||
//***************************************************************************
|
||||
namespace math
|
||||
{
|
||||
//***************************************************************************
|
||||
// floor
|
||||
//***************************************************************************
|
||||
ETL_NODISCARD
|
||||
inline float floor(float value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::floorf(value);
|
||||
}
|
||||
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline double floor(double value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::floor(value);
|
||||
}
|
||||
|
||||
#if ETL_USING_LONG_DOUBLE_MATH
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double floor(long double value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::floorl(value);
|
||||
}
|
||||
#else
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double floor(long double value) ETL_NOEXCEPT
|
||||
{
|
||||
return static_cast<long double>(::floor(static_cast<double>(value)));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
// ceil
|
||||
//***************************************************************************
|
||||
ETL_NODISCARD
|
||||
inline float ceil(float value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::ceilf(value);
|
||||
}
|
||||
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline double ceil(double value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::ceil(value);
|
||||
}
|
||||
|
||||
#if ETL_USING_LONG_DOUBLE_MATH
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double ceil(long double value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::ceill(value);
|
||||
}
|
||||
#else
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double ceil(long double value) ETL_NOEXCEPT
|
||||
{
|
||||
return static_cast<long double>(::ceil(static_cast<double>(value)));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
// log10
|
||||
//***************************************************************************
|
||||
ETL_NODISCARD
|
||||
inline float log10(float value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::log10f(value);
|
||||
}
|
||||
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline double log10(double value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::log10(value);
|
||||
}
|
||||
|
||||
#if ETL_USING_LONG_DOUBLE_MATH
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double log10(long double value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::log10l(value);
|
||||
}
|
||||
#else
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double log10(long double value) ETL_NOEXCEPT
|
||||
{
|
||||
return static_cast<long double>(::log10(static_cast<double>(value)));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
// round
|
||||
//***************************************************************************
|
||||
ETL_NODISCARD
|
||||
inline float round(float value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::roundf(value);
|
||||
}
|
||||
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline double round(double value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::round(value);
|
||||
}
|
||||
|
||||
#if ETL_USING_LONG_DOUBLE_MATH
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double round(long double value) ETL_NOEXCEPT
|
||||
{
|
||||
return ::roundl(value);
|
||||
}
|
||||
#else
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double round(long double value) ETL_NOEXCEPT
|
||||
{
|
||||
return static_cast<long double>(::round(static_cast<double>(value)));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
// power
|
||||
//***************************************************************************
|
||||
ETL_NODISCARD
|
||||
inline float pow(float base, float exponent) ETL_NOEXCEPT
|
||||
{
|
||||
return ::powf(base, exponent);
|
||||
}
|
||||
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline double pow(double base, double exponent) ETL_NOEXCEPT
|
||||
{
|
||||
return ::pow(base, exponent);
|
||||
}
|
||||
|
||||
#if ETL_USING_LONG_DOUBLE_MATH
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double pow(long double base, long double exponent) ETL_NOEXCEPT
|
||||
{
|
||||
return ::powl(base, exponent);
|
||||
}
|
||||
#else
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
inline long double pow(long double base, long double exponent) ETL_NOEXCEPT
|
||||
{
|
||||
return static_cast<long double>(::pow(static_cast<double>(base), static_cast<double>(exponent)));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
// modf
|
||||
//***************************************************************************
|
||||
inline float modf(float value, float* intpart) ETL_NOEXCEPT
|
||||
{
|
||||
return ::modff(value, intpart);
|
||||
}
|
||||
|
||||
//*********************************
|
||||
inline double modf(double value, double* intpart) ETL_NOEXCEPT
|
||||
{
|
||||
return ::modf(value, intpart);
|
||||
}
|
||||
|
||||
#if ETL_USING_LONG_DOUBLE_MATH
|
||||
//*********************************
|
||||
inline long double modf(long double value, long double* intpart) ETL_NOEXCEPT
|
||||
{
|
||||
return ::modfl(value, intpart);
|
||||
}
|
||||
#else
|
||||
//*********************************
|
||||
inline long double modf(long double value, long double* intpart) ETL_NOEXCEPT
|
||||
{
|
||||
double d_iptr;
|
||||
double result = ::modf(static_cast<double>(value), &d_iptr);
|
||||
*intpart = static_cast<long double>(d_iptr);
|
||||
|
||||
return static_cast<long double>(result);
|
||||
}
|
||||
#endif
|
||||
} // namespace math
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -175,16 +175,17 @@ SOFTWARE.
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Helper macro for ETL_FORMAT_NO_LONG_DOUBLE_MATH.
|
||||
// Define ETL_FORMAT_NO_LONG_DOUBLE_MATH if the toolchain does not provide
|
||||
// Helper macro for ETL_NO_LONG_DOUBLE_MATH.
|
||||
// Define ETL_NO_LONG_DOUBLE_MATH if the toolchain does not provide
|
||||
// long double math functions (log10l, floorl, powl, modfl, roundl).
|
||||
// When defined, long double arguments are cast to double for math operations.
|
||||
#if defined(ETL_FORMAT_NO_LONG_DOUBLE_MATH)
|
||||
#define ETL_USING_FORMAT_LONG_DOUBLE_MATH 0
|
||||
#define ETL_NOT_USING_FORMAT_LONG_DOUBLE_MATH 1
|
||||
// ETL_FORMAT_NO_LONG_DOUBLE_MATH is deprecated, but still supported for backwards compatibility.
|
||||
#if defined(ETL_NO_LONG_DOUBLE_MATH) || defined(ETL_FORMAT_NO_LONG_DOUBLE_MATH)
|
||||
#define ETL_USING_LONG_DOUBLE_MATH 0
|
||||
#define ETL_NOT_USING_LONG_DOUBLE_MATH 1
|
||||
#else
|
||||
#define ETL_USING_FORMAT_LONG_DOUBLE_MATH 1
|
||||
#define ETL_NOT_USING_FORMAT_LONG_DOUBLE_MATH 0
|
||||
#define ETL_USING_LONG_DOUBLE_MATH 1
|
||||
#define ETL_NOT_USING_LONG_DOUBLE_MATH 0
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
|
||||
@ -44,8 +44,6 @@ SOFTWARE.
|
||||
#include "../negative.h"
|
||||
#include "../type_traits.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
#include <iterator> // For std::begin, std::end and std::size
|
||||
#endif
|
||||
@ -347,11 +345,11 @@ namespace etl
|
||||
}
|
||||
|
||||
// Find the integral part of the floating point
|
||||
T f_integral = ::floor(scaled);
|
||||
T f_integral = etl::math::floor(scaled);
|
||||
uworkspace_t integral = static_cast<uworkspace_t>(f_integral);
|
||||
|
||||
// Find the fractional part of the floating point.
|
||||
uworkspace_t fractional = static_cast<uworkspace_t>(::round((scaled - f_integral) * multiplier));
|
||||
uworkspace_t fractional = static_cast<uworkspace_t>(etl::math::round((scaled - f_integral) * multiplier));
|
||||
|
||||
// Check for a rounding carry to the integral.
|
||||
if (fractional == multiplier)
|
||||
@ -404,7 +402,7 @@ namespace etl
|
||||
}
|
||||
|
||||
// Find the integral part of the floating point
|
||||
T f_integral = ::floor(etl::absolute(value));
|
||||
T f_integral = etl::math::floor(etl::absolute(value));
|
||||
uworkspace_t integral = static_cast<uworkspace_t>(f_integral);
|
||||
|
||||
// Find the fractional part of the floating point.
|
||||
|
||||
@ -130,5 +130,120 @@ namespace
|
||||
CHECK_TRUE(etl::is_exactly_equal(i1, i1));
|
||||
CHECK_FALSE(etl::is_exactly_equal(i1, i2));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floor)
|
||||
{
|
||||
float f1 = 1.7f;
|
||||
float f2 = -1.7f;
|
||||
double d1 = 1.7;
|
||||
double d2 = -1.7;
|
||||
long double ld1 = 1.7L;
|
||||
long double ld2 = -1.7L;
|
||||
|
||||
CHECK_CLOSE(1.0f, etl::math::floor(f1), 0.0001f);
|
||||
CHECK_CLOSE(-2.0f, etl::math::floor(f2), 0.0001f);
|
||||
CHECK_CLOSE(1.0, etl::math::floor(d1), 0.0001);
|
||||
CHECK_CLOSE(-2.0, etl::math::floor(d2), 0.0001);
|
||||
CHECK_CLOSE(1.0L, etl::math::floor(ld1), 0.0001L);
|
||||
CHECK_CLOSE(-2.0L, etl::math::floor(ld2), 0.0001L);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_ceil)
|
||||
{
|
||||
float f1 = 1.2f;
|
||||
float f2 = -1.2f;
|
||||
double d1 = 1.2;
|
||||
double d2 = -1.2;
|
||||
long double ld1 = 1.2L;
|
||||
long double ld2 = -1.2L;
|
||||
|
||||
CHECK_CLOSE(2.0f, etl::math::ceil(f1), 0.0001f);
|
||||
CHECK_CLOSE(-1.0f, etl::math::ceil(f2), 0.0001f);
|
||||
CHECK_CLOSE(2.0, etl::math::ceil(d1), 0.0001);
|
||||
CHECK_CLOSE(-1.0, etl::math::ceil(d2), 0.0001);
|
||||
CHECK_CLOSE(2.0L, etl::math::ceil(ld1), 0.0001L);
|
||||
CHECK_CLOSE(-1.0L, etl::math::ceil(ld2), 0.0001L);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_log10)
|
||||
{
|
||||
float f1 = 100.0f;
|
||||
double d1 = 1000.0;
|
||||
long double ld1 = 10000.0L;
|
||||
|
||||
CHECK_CLOSE(2.0f, etl::math::log10(f1), 0.0001f);
|
||||
CHECK_CLOSE(3.0, etl::math::log10(d1), 0.0001);
|
||||
CHECK_CLOSE(4.0L, etl::math::log10(ld1), 0.0001L);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_round)
|
||||
{
|
||||
float f1 = 1.5f;
|
||||
float f2 = -1.5f;
|
||||
float f3 = 1.4f;
|
||||
float f4 = -1.4f;
|
||||
double d1 = 2.5;
|
||||
double d2 = -2.5;
|
||||
double d3 = 2.4;
|
||||
double d4 = -2.4;
|
||||
long double ld1 = 3.5L;
|
||||
long double ld2 = -3.5L;
|
||||
long double ld3 = 3.4L;
|
||||
long double ld4 = -3.4L;
|
||||
|
||||
CHECK_CLOSE(2.0f, etl::math::round(f1), 0.0001f);
|
||||
CHECK_CLOSE(-2.0f, etl::math::round(f2), 0.0001f);
|
||||
CHECK_CLOSE(1.0f, etl::math::round(f3), 0.0001f);
|
||||
CHECK_CLOSE(-1.0f, etl::math::round(f4), 0.0001f);
|
||||
CHECK_CLOSE(3.0, etl::math::round(d1), 0.0001);
|
||||
CHECK_CLOSE(-3.0, etl::math::round(d2), 0.0001);
|
||||
CHECK_CLOSE(2.0, etl::math::round(d3), 0.0001);
|
||||
CHECK_CLOSE(-2.0, etl::math::round(d4), 0.0001);
|
||||
CHECK_CLOSE(4.0L, etl::math::round(ld1), 0.0001L);
|
||||
CHECK_CLOSE(-4.0L, etl::math::round(ld2), 0.0001L);
|
||||
CHECK_CLOSE(3.0L, etl::math::round(ld3), 0.0001L);
|
||||
CHECK_CLOSE(-3.0L, etl::math::round(ld4), 0.0001L);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pow)
|
||||
{
|
||||
float fb = 2.0f;
|
||||
float fe = 3.0f;
|
||||
double db = 2.0;
|
||||
double de = 10.0;
|
||||
long double ldb = 2.0L;
|
||||
long double lde = 4.0L;
|
||||
|
||||
CHECK_CLOSE(8.0f, etl::math::pow(fb, fe), 0.0001f);
|
||||
CHECK_CLOSE(1024.0, etl::math::pow(db, de), 0.0001);
|
||||
CHECK_CLOSE(16.0L, etl::math::pow(ldb, lde), 0.0001L);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_modf)
|
||||
{
|
||||
float f1 = 3.75f;
|
||||
float f_intpart = 0.0f;
|
||||
double d1 = 3.75;
|
||||
double d_intpart = 0.0;
|
||||
long double ld1 = 3.75L;
|
||||
long double ld_intpart = 0.0L;
|
||||
|
||||
float f_frac = etl::math::modf(f1, &f_intpart);
|
||||
double d_frac = etl::math::modf(d1, &d_intpart);
|
||||
long double ld_frac = etl::math::modf(ld1, &ld_intpart);
|
||||
|
||||
CHECK_CLOSE(3.0f, f_intpart, 0.0001f);
|
||||
CHECK_CLOSE(0.75f, f_frac, 0.0001f);
|
||||
CHECK_CLOSE(3.0, d_intpart, 0.0001);
|
||||
CHECK_CLOSE(0.75, d_frac, 0.0001);
|
||||
CHECK_CLOSE((double)3.0L, (double)ld_intpart, 0.0001);
|
||||
CHECK_CLOSE((double)0.75L, (double)ld_frac, 0.0001);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -181,10 +181,21 @@ namespace
|
||||
ss << etl::noboolalpha << false << STR(" ") << true << STR(" ") << etl::boolalpha << false << STR(" ") << true;
|
||||
CHECK_EQUAL(String(STR("0 1 false true")), ss.str());
|
||||
|
||||
// Float
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927f;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
// Double
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
// Long double
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927l;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << STR("abcdef") << STR(" ") << etl::uppercase << STR("abcdef");
|
||||
CHECK_EQUAL(String(STR("abcdef abcdef")), ss.str());
|
||||
|
||||
@ -181,10 +181,18 @@ namespace
|
||||
ss << etl::noboolalpha << false << STR(" ") << true << STR(" ") << etl::boolalpha << false << STR(" ") << true;
|
||||
CHECK_EQUAL(String(STR("0 1 false true")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927f;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927l;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << STR("abcdef") << STR(" ") << etl::uppercase << STR("abcdef");
|
||||
CHECK_EQUAL(String(STR("abcdef abcdef")), ss.str());
|
||||
|
||||
@ -181,10 +181,18 @@ namespace
|
||||
ss << etl::noboolalpha << false << STR(" ") << true << STR(" ") << etl::boolalpha << false << STR(" ") << true;
|
||||
CHECK_EQUAL(String(STR("0 1 false true")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927f;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927l;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << STR("abcdef") << STR(" ") << etl::uppercase << STR("abcdef");
|
||||
CHECK_EQUAL(String(STR("abcdef abcdef")), ss.str());
|
||||
|
||||
@ -184,10 +184,18 @@ namespace
|
||||
ss << etl::noboolalpha << false << STR(" ") << true << STR(" ") << etl::boolalpha << false << STR(" ") << true;
|
||||
CHECK_EQUAL(String(STR("0 1 false true")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927f;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927l;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << STR("abcdef") << STR(" ") << etl::uppercase << STR("abcdef");
|
||||
CHECK_EQUAL(String(STR("abcdef abcdef")), ss.str());
|
||||
|
||||
@ -182,10 +182,18 @@ namespace
|
||||
ss << etl::noboolalpha << false << STR(" ") << true << STR(" ") << etl::boolalpha << false << STR(" ") << true;
|
||||
CHECK_EQUAL(String(STR("0 1 false true")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927f;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << etl::setprecision(4) << 3.1415927l;
|
||||
CHECK_EQUAL(String(STR("3.1416")), ss.str());
|
||||
|
||||
ss.str().clear();
|
||||
ss << STR("abcdef") << STR(" ") << etl::uppercase << STR("abcdef");
|
||||
CHECK_EQUAL(String(STR("abcdef abcdef")), ss.str());
|
||||
|
||||
@ -44,32 +44,35 @@ namespace
|
||||
{
|
||||
typedef etl::format_spec Format;
|
||||
|
||||
using String20 = etl::string<20>;
|
||||
using String64 = etl::string<64>;
|
||||
|
||||
SUITE(test_to_string)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_default_format_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::string<20>(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(etl::string<20>(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(etl::string<20>(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(etl::string<20>(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
|
||||
CHECK(etl::string<20>(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(etl::string<20>(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
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(String20(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(String20(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
CHECK(String20(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str));
|
||||
CHECK(String20(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str));
|
||||
|
||||
CHECK(etl::string<20>(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(etl::string<20>(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(etl::string<20>(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(etl::string<20>(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
CHECK(String20(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(String20(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(String20(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(String20(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
|
||||
CHECK(etl::string<20>(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(etl::string<20>(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(etl::string<20>(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
CHECK(String20(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(String20(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(String20(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -107,89 +110,89 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_format_right_justified_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
Format format = Format().base(10).width(20).fill(STR('#'));
|
||||
|
||||
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));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::string<20>(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::string<20>(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
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(String20(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::string<20>(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::string<20>(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::string<20>(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::string<20>(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::string<20>(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::string<20>(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::string<20>(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_format_left_justified_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
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(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));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::string<20>(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::string<20>(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
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(String20(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::string<20>(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::string<20>(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::string<20>(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::string<20>(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::string<20>(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::string<20>(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::string<20>(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_binary_format_no_append)
|
||||
{
|
||||
etl::string<64> str;
|
||||
String64 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("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"))
|
||||
CHECK(String64(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::string<64>(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("10000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000"))
|
||||
== etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(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_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
CHECK(String64(STR("01111111")) == etl::to_string(INT8_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
== etl::to_string(INT64_MAX, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::string<64>(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(INT64_MIN, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
}
|
||||
|
||||
@ -261,126 +264,126 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::string<20>(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::string<20>(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::string<20>(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::string<20>(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::string<20>(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::string<20>(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::string<20>(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::string<20>(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::string<20>(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::string<20>(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::string<20>(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(etl::string<20>(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
CHECK(String20(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(String20(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
|
||||
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()));
|
||||
CHECK(String20(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(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()));
|
||||
CHECK(String20(STR(" 2.000000")) == etl::to_string(1.9999996, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(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()));
|
||||
CHECK(String20(STR(" -2.000000")) == etl::to_string(-1.9999996, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("-2.000000 ")) == etl::to_string(-1.9999996, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
CHECK(String20(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
CHECK(String20(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
CHECK(String20(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_rounding)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::string<20>(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(etl::string<20>(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(etl::string<20>(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(etl::string<20>(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(etl::string<20>(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::string<20>(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::string<20>(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::string<20>(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::string<20>(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(etl::string<20>(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(String20(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(String20(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(String20(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(String20(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::string<20>(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::string<20>(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::string<20>(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(etl::string<20>(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK(etl::string<20>(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::string<20>(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::string<20>(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(etl::string<20>(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_no_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
static const volatile int cvi = 0;
|
||||
|
||||
@ -388,8 +391,8 @@ namespace
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::right << uintptr_t(&cvi);
|
||||
std::string temp(oss.str());
|
||||
etl::string<20> compare(temp.begin(), temp.end());
|
||||
std::string temp(oss.str());
|
||||
String20 compare(temp.begin(), temp.end());
|
||||
|
||||
to_string(&cvi, str, Format().hex().width(10).right().fill(STR('0')));
|
||||
CHECK(compare == str);
|
||||
@ -409,7 +412,7 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_append)
|
||||
{
|
||||
etl::string<20> str;
|
||||
String20 str;
|
||||
|
||||
static const volatile int cvi = 0;
|
||||
|
||||
@ -419,7 +422,7 @@ namespace
|
||||
oss << std::hex << std::right << uintptr_t(&cvi);
|
||||
std::string temp(STR("Result "));
|
||||
temp.append(oss.str());
|
||||
etl::string<20> compare(temp.begin(), temp.end());
|
||||
String20 compare(temp.begin(), temp.end());
|
||||
|
||||
str.assign(STR("Result "));
|
||||
to_string(&cvi, str, Format().hex().width(10).right().fill(STR('0')), true);
|
||||
@ -442,229 +445,229 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_default_format)
|
||||
{
|
||||
etl::string<20> result;
|
||||
int value = -1234567;
|
||||
String20 result;
|
||||
int value = -1234567;
|
||||
|
||||
etl::to_string(value, 6U, result);
|
||||
|
||||
CHECK_EQUAL(etl::string<20>(STR("-1")).c_str(), result.c_str());
|
||||
CHECK_EQUAL(String20(STR("-1")).c_str(), result.c_str());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision)
|
||||
{
|
||||
etl::string<20> result;
|
||||
int value = -1234560;
|
||||
String20 result;
|
||||
int value = -1234560;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 6U, result, format);
|
||||
|
||||
CHECK_EQUAL(etl::string<20>(STR("-1.234560")).c_str(), result.c_str());
|
||||
CHECK_EQUAL(String20(STR("-1.234560")).c_str(), result.c_str());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision_64bit)
|
||||
{
|
||||
etl::string<20> result;
|
||||
int64_t value = INT64_MIN;
|
||||
String20 result;
|
||||
int64_t value = INT64_MIN;
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(STR("-9223372.036854775808")).c_str(), result.c_str());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_fractional)
|
||||
{
|
||||
etl::string<20> result_i;
|
||||
int value_i = -1000000;
|
||||
String20 result_i;
|
||||
int value_i = -1000000;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -1.000000;
|
||||
String20 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_EQUAL(etl::string<20>(STR("-1.0000")).c_str(), result_i.c_str());
|
||||
CHECK_EQUAL(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = 0;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -0.000000;
|
||||
String20 result_d;
|
||||
double value_d = -0.000000;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -400;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -0.000400;
|
||||
String20 result_d;
|
||||
double value_d = -0.000400;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000400;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -123.000400;
|
||||
String20 result_d;
|
||||
double value_d = -123.000400;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000004;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -123.000004;
|
||||
String20 result_d;
|
||||
double value_d = -123.000004;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000050;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -123.000050;
|
||||
String20 result_d;
|
||||
double value_d = -123.000050;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(6).right();
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(STR("-123.4568")).c_str(), result_i.c_str());
|
||||
CHECK_EQUAL(result_d.c_str(), result_i.c_str());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_double_formatting_10_decimal_point)
|
||||
{
|
||||
etl::string<20> result_d;
|
||||
double value_d = 1.2345;
|
||||
String20 result_d;
|
||||
double value_d = 1.2345;
|
||||
|
||||
Format format = Format().precision(10);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK_EQUAL(etl::string<20>(STR("1.2345000000")).c_str(), result_d.c_str());
|
||||
CHECK_EQUAL(String20(STR("1.2345000000")).c_str(), result_d.c_str());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_larger_width)
|
||||
{
|
||||
etl::string<20> result_i;
|
||||
int value_i = -123456780;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(15).right();
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(STR(" -123.4568")).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 = 123999990;
|
||||
String20 result_i;
|
||||
int value_i = 123999990;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = 123.999990;
|
||||
String20 result_d;
|
||||
double value_d = 123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(STR("124.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 = -123999990;
|
||||
String20 result_i;
|
||||
int value_i = -123999990;
|
||||
|
||||
etl::string<20> result_d;
|
||||
double value_d = -123.999990;
|
||||
String20 result_d;
|
||||
double value_d = -123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
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());
|
||||
CHECK_EQUAL(String20(STR("-124.0000")).c_str(), result_i.c_str());
|
||||
CHECK_EQUAL(result_d.c_str(), result_i.c_str());
|
||||
}
|
||||
|
||||
@ -674,48 +677,48 @@ namespace
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
// Check forced scientific formatting for smaller numbers.
|
||||
etl::string<64> s0;
|
||||
String64 s0;
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true));
|
||||
CHECK(etl::string<64>(STR(" 1.00000e+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000e+3")) == s0);
|
||||
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::string<64>(STR(" 1.00000E+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000E+3")) == s0);
|
||||
|
||||
// Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision.
|
||||
etl::string<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::max(), s1, Format().precision(5).width(15).right());
|
||||
CHECK(etl::string<64>(STR(" 1.79769e+308")) == s1);
|
||||
CHECK(String64(STR(" 1.79769e+308")) == s1);
|
||||
|
||||
// Negative maximum double value is -1.7976931348623157e+308, which rounds to -1.79769e+308 with 5 digits of precision.
|
||||
etl::string<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(-std::numeric_limits<double>::max(), s2, Format().precision(5).width(15).right());
|
||||
CHECK(etl::string<64>(STR(" -1.79769e+308")) == s2);
|
||||
CHECK(String64(STR(" -1.79769e+308")) == s2);
|
||||
}
|
||||
|
||||
#if ETL_USING_64BIT_TYPES
|
||||
using workspace_t = etl::private_to_string::workspace_t;
|
||||
|
||||
// Maximum workspace_t value is 9223372036854775807.
|
||||
etl::string<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::max(), s3, Format().precision(5).width(21).right());
|
||||
CHECK(etl::string<64>(STR(" 9223372036854775807")) == s3);
|
||||
CHECK(String64(STR(" 9223372036854775807")) == s3);
|
||||
|
||||
// Minimum workspace_t value is -9223372036854775808.
|
||||
etl::string<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::min(), s4, Format().precision(5).width(21).right());
|
||||
CHECK(etl::string<64>(STR(" -9223372036854775808")) == s4);
|
||||
CHECK(String64(STR(" -9223372036854775808")) == s4);
|
||||
|
||||
using uworkspace_t = etl::private_to_string::uworkspace_t;
|
||||
|
||||
// Maximum uworkspace_t value is 18446744073709551615.
|
||||
etl::string<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::max(), s5, Format().precision(5).width(21).right());
|
||||
CHECK(etl::string<64>(STR(" 18446744073709551615")) == s5);
|
||||
CHECK(String64(STR(" 18446744073709551615")) == s5);
|
||||
|
||||
// Minimum uworkspace_t value is 0.
|
||||
etl::string<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::min(), s6, Format().precision(5).width(21).right());
|
||||
CHECK(etl::string<64>(STR(" 0")) == s6);
|
||||
CHECK(String64(STR(" 0")) == s6);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -724,30 +727,48 @@ namespace
|
||||
{
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
etl::string<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::string<64>(STR(" nan")) == s1);
|
||||
CHECK(String64(STR(" nan")) == s1);
|
||||
|
||||
etl::string<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::string<64>(STR(" inf")) == s2);
|
||||
CHECK(String64(STR(" inf")) == s2);
|
||||
|
||||
etl::string<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::string<64>(STR(" -inf")) == s3);
|
||||
CHECK(String64(STR(" -inf")) == s3);
|
||||
|
||||
etl::string<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::string<64>(STR(" NAN")) == s4);
|
||||
CHECK(String64(STR(" NAN")) == s4);
|
||||
|
||||
etl::string<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::string<64>(STR(" INF")) == s5);
|
||||
CHECK(String64(STR(" INF")) == s5);
|
||||
|
||||
etl::string<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::string<64>(STR(" -INF")) == s6);
|
||||
CHECK(String64(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_1593_to_string_float_uses_double_math)
|
||||
{
|
||||
String64 s1;
|
||||
|
||||
// Float
|
||||
etl::to_string(3.1415927f, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Double
|
||||
etl::to_string(3.1415927, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Long double
|
||||
etl::to_string(3.1415927l, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -41,32 +41,35 @@ namespace
|
||||
{
|
||||
typedef etl::u16format_spec Format;
|
||||
|
||||
using String20 = etl::u16string<20>;
|
||||
using String64 = etl::u16string<64>;
|
||||
|
||||
SUITE(test_to_u16string)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_default_format_no_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u16string<20>(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(etl::u16string<20>(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(etl::u16string<20>(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(etl::u16string<20>(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(etl::u16string<20>(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
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(String20(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(String20(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
CHECK(String20(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str));
|
||||
CHECK(String20(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(etl::u16string<20>(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(etl::u16string<20>(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(etl::u16string<20>(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
CHECK(String20(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(String20(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(String20(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(String20(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(etl::u16string<20>(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(etl::u16string<20>(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
CHECK(String20(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(String20(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(String20(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -104,88 +107,87 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_format_right_justified_no_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
String20 str;
|
||||
|
||||
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(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));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::u16string<20>(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
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(String20(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::u16string<20>(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::u16string<20>(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::u16string<20>(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::u16string<20>(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::u16string<20>(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_format_left_justified_no_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
String20 str;
|
||||
|
||||
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(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));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::u16string<20>(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
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(String20(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::u16string<20>(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::u16string<20>(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::u16string<20>(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::u16string<20>(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::u16string<20>(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::u16string<20>(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::u16string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_binary_format_no_append)
|
||||
{
|
||||
etl::u16string<64> str;
|
||||
String64 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("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"))
|
||||
CHECK(String64(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::u16string<64>(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("10000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000"))
|
||||
== etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(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_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
CHECK(String64(STR("01111111")) == etl::to_string(INT8_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
== etl::to_string(INT64_MAX, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::u16string<64>(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u16string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(INT64_MIN, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
}
|
||||
|
||||
@ -257,328 +259,328 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u16string<20>(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u16string<20>(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u16string<20>(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u16string<20>(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u16string<20>(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(etl::u16string<20>(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
CHECK(String20(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(String20(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u16string<20>(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
CHECK(String20(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
CHECK(String20(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
CHECK(String20(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_rounding)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u16string<20>(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(etl::u16string<20>(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(etl::u16string<20>(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(etl::u16string<20>(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(etl::u16string<20>(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::u16string<20>(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::u16string<20>(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::u16string<20>(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::u16string<20>(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(etl::u16string<20>(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(String20(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(String20(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(String20(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(String20(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::u16string<20>(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::u16string<20>(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(etl::u16string<20>(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK(etl::u16string<20>(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::u16string<20>(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::u16string<20>(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(etl::u16string<20>(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::u16string<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u16string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(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;
|
||||
String20 result;
|
||||
int value = -1234567;
|
||||
|
||||
etl::to_string(value, 6U, result);
|
||||
|
||||
CHECK(etl::u16string<20>(STR("-1")) == result);
|
||||
CHECK(String20(STR("-1")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision)
|
||||
{
|
||||
etl::u16string<20> result;
|
||||
int value = -1234560;
|
||||
String20 result;
|
||||
int value = -1234560;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 6U, result, format);
|
||||
|
||||
CHECK(etl::u16string<20>(STR("-1.234560")) == result);
|
||||
CHECK(String20(STR("-1.234560")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision_64bit)
|
||||
{
|
||||
etl::u16string<20> result;
|
||||
int64_t value = INT64_MIN;
|
||||
String20 result;
|
||||
int64_t value = INT64_MIN;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 12U, result, format);
|
||||
|
||||
CHECK(etl::u16string<20>(STR("-9223372.036854775808")) == result);
|
||||
CHECK(String20(STR("-9223372.036854775808")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_fractional)
|
||||
{
|
||||
etl::u16string<20> result_i;
|
||||
int value_i = -1000000;
|
||||
String20 result_i;
|
||||
int value_i = -1000000;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -1.000000;
|
||||
String20 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(String20(STR("-1.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_value)
|
||||
{
|
||||
etl::u16string<20> result_i;
|
||||
int value_i = 0;
|
||||
String20 result_i;
|
||||
int value_i = 0;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -0.000000;
|
||||
String20 result_d;
|
||||
double value_d = -0.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("0.0000")) == result_i);
|
||||
CHECK(String20(STR("0.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_integral_small_fractional)
|
||||
{
|
||||
etl::u16string<20> result_i;
|
||||
int value_i = -400;
|
||||
String20 result_i;
|
||||
int value_i = -400;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -0.000400;
|
||||
String20 result_d;
|
||||
double value_d = -0.000400;
|
||||
|
||||
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("-0.0004")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000400;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -123.000400;
|
||||
String20 result_d;
|
||||
double value_d = -123.000400;
|
||||
|
||||
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("-123.0004")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000004;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -123.000004;
|
||||
String20 result_d;
|
||||
double value_d = -123.000004;
|
||||
|
||||
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("-123.0000")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000050;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -123.000050;
|
||||
String20 result_d;
|
||||
double value_d = -123.000050;
|
||||
|
||||
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("-123.0001")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(6).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(15).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = 123999990;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = 123.999990;
|
||||
String20 result_d;
|
||||
double value_d = 123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123999990;
|
||||
|
||||
etl::u16string<20> result_d;
|
||||
double value_d = -123.999990;
|
||||
String20 result_d;
|
||||
double value_d = -123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(STR("-124.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
@ -588,48 +590,48 @@ namespace
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
// Check forced scientific formatting for smaller numbers.
|
||||
etl::u16string<64> s0;
|
||||
String64 s0;
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true));
|
||||
CHECK(etl::u16string<64>(STR(" 1.00000e+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000e+3")) == s0);
|
||||
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u16string<64>(STR(" 1.00000E+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000E+3")) == s0);
|
||||
|
||||
// Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision.
|
||||
etl::u16string<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::max(), s1, Format().precision(5).width(15).right());
|
||||
CHECK(etl::u16string<64>(STR(" 1.79769e+308")) == s1);
|
||||
CHECK(String64(STR(" 1.79769e+308")) == s1);
|
||||
|
||||
// Negative maximum double value is -1.7976931348623157e+308, which rounds to -1.79769e+308 with 5 digits of precision.
|
||||
etl::u16string<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(-std::numeric_limits<double>::max(), s2, Format().precision(5).width(15).right());
|
||||
CHECK(etl::u16string<64>(STR(" -1.79769e+308")) == s2);
|
||||
CHECK(String64(STR(" -1.79769e+308")) == s2);
|
||||
}
|
||||
|
||||
#if ETL_USING_64BIT_TYPES
|
||||
using workspace_t = etl::private_to_string::workspace_t;
|
||||
|
||||
// Maximum workspace_t value is 9223372036854775807.
|
||||
etl::u16string<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::max(), s3, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u16string<64>(STR(" 9223372036854775807")) == s3);
|
||||
CHECK(String64(STR(" 9223372036854775807")) == s3);
|
||||
|
||||
// Minimum workspace_t value is -9223372036854775808.
|
||||
etl::u16string<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::min(), s4, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u16string<64>(STR(" -9223372036854775808")) == s4);
|
||||
CHECK(String64(STR(" -9223372036854775808")) == s4);
|
||||
|
||||
using uworkspace_t = etl::private_to_string::uworkspace_t;
|
||||
|
||||
// Maximum uworkspace_t value is 18446744073709551615.
|
||||
etl::u16string<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::max(), s5, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u16string<64>(STR(" 18446744073709551615")) == s5);
|
||||
CHECK(String64(STR(" 18446744073709551615")) == s5);
|
||||
|
||||
// Minimum uworkspace_t value is 0.
|
||||
etl::u16string<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::min(), s6, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u16string<64>(STR(" 0")) == s6);
|
||||
CHECK(String64(STR(" 0")) == s6);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -638,30 +640,48 @@ namespace
|
||||
{
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
etl::u16string<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u16string<64>(STR(" nan")) == s1);
|
||||
CHECK(String64(STR(" nan")) == s1);
|
||||
|
||||
etl::u16string<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u16string<64>(STR(" inf")) == s2);
|
||||
CHECK(String64(STR(" inf")) == s2);
|
||||
|
||||
etl::u16string<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u16string<64>(STR(" -inf")) == s3);
|
||||
CHECK(String64(STR(" -inf")) == s3);
|
||||
|
||||
etl::u16string<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u16string<64>(STR(" NAN")) == s4);
|
||||
CHECK(String64(STR(" NAN")) == s4);
|
||||
|
||||
etl::u16string<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u16string<64>(STR(" INF")) == s5);
|
||||
CHECK(String64(STR(" INF")) == s5);
|
||||
|
||||
etl::u16string<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u16string<64>(STR(" -INF")) == s6);
|
||||
CHECK(String64(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_1593_to_string_float_uses_double_math)
|
||||
{
|
||||
String64 s1;
|
||||
|
||||
// Float
|
||||
etl::to_string(3.1415927f, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Double
|
||||
etl::to_string(3.1415927, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Long double
|
||||
etl::to_string(3.1415927l, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -42,32 +42,35 @@ namespace
|
||||
{
|
||||
typedef etl::u32format_spec Format;
|
||||
|
||||
using String20 = etl::u32string<20>;
|
||||
using String64 = etl::u32string<64>;
|
||||
|
||||
SUITE(test_to_u32string)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_default_format_no_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u32string<20>(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(etl::u32string<20>(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(etl::u32string<20>(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(etl::u32string<20>(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(etl::u32string<20>(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
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(String20(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(String20(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
CHECK(String20(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str));
|
||||
CHECK(String20(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(etl::u32string<20>(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(etl::u32string<20>(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(etl::u32string<20>(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
CHECK(String20(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(String20(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(String20(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(String20(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(etl::u32string<20>(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(etl::u32string<20>(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
CHECK(String20(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(String20(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(String20(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -105,88 +108,87 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_format_right_justified_no_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
String20 str;
|
||||
|
||||
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(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));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::u32string<20>(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
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(String20(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::u32string<20>(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::u32string<20>(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::u32string<20>(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::u32string<20>(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::u32string<20>(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_format_left_justified_no_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
String20 str;
|
||||
|
||||
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(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));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::u32string<20>(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
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(String20(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::u32string<20>(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::u32string<20>(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::u32string<20>(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::u32string<20>(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::u32string<20>(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::u32string<20>(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::u32string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_binary_format_no_append)
|
||||
{
|
||||
etl::u32string<64> str;
|
||||
String64 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("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"))
|
||||
CHECK(String64(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::u32string<64>(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("10000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000"))
|
||||
== etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(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_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
CHECK(String64(STR("01111111")) == etl::to_string(INT8_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
== etl::to_string(INT64_MAX, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::u32string<64>(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u32string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(INT64_MIN, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
}
|
||||
|
||||
@ -258,329 +260,329 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u32string<20>(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u32string<20>(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u32string<20>(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u32string<20>(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u32string<20>(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(etl::u32string<20>(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
CHECK(String20(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(String20(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u32string<20>(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
CHECK(String20(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
CHECK(String20(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
CHECK(String20(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_rounding)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u32string<20>(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(etl::u32string<20>(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(etl::u32string<20>(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(etl::u32string<20>(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(etl::u32string<20>(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::u32string<20>(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::u32string<20>(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::u32string<20>(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(etl::u32string<20>(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::u32string<20>(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(etl::u32string<20>(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(String20(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(String20(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(String20(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(String20(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::u32string<20>(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::u32string<20>(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(etl::u32string<20>(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK(etl::u32string<20>(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::u32string<20>(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::u32string<20>(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(etl::u32string<20>(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::u32string<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u32string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(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;
|
||||
String20 result;
|
||||
int value = -1234567;
|
||||
|
||||
etl::to_string(value, 6U, result);
|
||||
|
||||
CHECK(etl::u32string<20>(STR("-1")) == result);
|
||||
CHECK(String20(STR("-1")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision)
|
||||
{
|
||||
etl::u32string<20> result;
|
||||
int value = -1234560;
|
||||
String20 result;
|
||||
int value = -1234560;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 6U, result, format);
|
||||
|
||||
CHECK(etl::u32string<20>(STR("-1.234560")) == result);
|
||||
CHECK(String20(STR("-1.234560")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision_64bit)
|
||||
{
|
||||
etl::u32string<20> result;
|
||||
int64_t value = INT64_MIN;
|
||||
String20 result;
|
||||
int64_t value = INT64_MIN;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 12U, result, format);
|
||||
|
||||
CHECK(etl::u32string<20>(STR("-9223372.036854775808")) == result);
|
||||
CHECK(String20(STR("-9223372.036854775808")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_fractional)
|
||||
{
|
||||
etl::u32string<20> result_i;
|
||||
int value_i = -1000000;
|
||||
String20 result_i;
|
||||
int value_i = -1000000;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -1.000000;
|
||||
String20 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(String20(STR("-1.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_value)
|
||||
{
|
||||
etl::u32string<20> result_i;
|
||||
int value_i = 0;
|
||||
String20 result_i;
|
||||
int value_i = 0;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -0.000000;
|
||||
String20 result_d;
|
||||
double value_d = -0.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("0.0000")) == result_i);
|
||||
CHECK(String20(STR("0.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_integral_small_fractional)
|
||||
{
|
||||
etl::u32string<20> result_i;
|
||||
int value_i = -400;
|
||||
String20 result_i;
|
||||
int value_i = -400;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -0.000400;
|
||||
String20 result_d;
|
||||
double value_d = -0.000400;
|
||||
|
||||
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("-0.0004")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000400;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -123.000400;
|
||||
String20 result_d;
|
||||
double value_d = -123.000400;
|
||||
|
||||
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("-123.0004")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000004;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -123.000004;
|
||||
String20 result_d;
|
||||
double value_d = -123.000004;
|
||||
|
||||
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("-123.0000")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000050;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -123.000050;
|
||||
String20 result_d;
|
||||
double value_d = -123.000050;
|
||||
|
||||
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("-123.0001")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(6).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(15).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = 123999990;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = 123.999990;
|
||||
String20 result_d;
|
||||
double value_d = 123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123999990;
|
||||
|
||||
etl::u32string<20> result_d;
|
||||
double value_d = -123.999990;
|
||||
String20 result_d;
|
||||
double value_d = -123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(STR("-124.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
@ -590,48 +592,48 @@ namespace
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
// Check forced scientific formatting for smaller numbers.
|
||||
etl::u32string<64> s0;
|
||||
String64 s0;
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true));
|
||||
CHECK(etl::u32string<64>(STR(" 1.00000e+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000e+3")) == s0);
|
||||
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u32string<64>(STR(" 1.00000E+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000E+3")) == s0);
|
||||
|
||||
// Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision.
|
||||
etl::u32string<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::max(), s1, Format().precision(5).width(15).right());
|
||||
CHECK(etl::u32string<64>(STR(" 1.79769e+308")) == s1);
|
||||
CHECK(String64(STR(" 1.79769e+308")) == s1);
|
||||
|
||||
// Negative maximum double value is -1.7976931348623157e+308, which rounds to -1.79769e+308 with 5 digits of precision.
|
||||
etl::u32string<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(-std::numeric_limits<double>::max(), s2, Format().precision(5).width(15).right());
|
||||
CHECK(etl::u32string<64>(STR(" -1.79769e+308")) == s2);
|
||||
CHECK(String64(STR(" -1.79769e+308")) == s2);
|
||||
}
|
||||
|
||||
#if ETL_USING_64BIT_TYPES
|
||||
using workspace_t = etl::private_to_string::workspace_t;
|
||||
|
||||
// Maximum workspace_t value is 9223372036854775807.
|
||||
etl::u32string<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::max(), s3, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u32string<64>(STR(" 9223372036854775807")) == s3);
|
||||
CHECK(String64(STR(" 9223372036854775807")) == s3);
|
||||
|
||||
// Minimum workspace_t value is -9223372036854775808.
|
||||
etl::u32string<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::min(), s4, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u32string<64>(STR(" -9223372036854775808")) == s4);
|
||||
CHECK(String64(STR(" -9223372036854775808")) == s4);
|
||||
|
||||
using uworkspace_t = etl::private_to_string::uworkspace_t;
|
||||
|
||||
// Maximum uworkspace_t value is 18446744073709551615.
|
||||
etl::u32string<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::max(), s5, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u32string<64>(STR(" 18446744073709551615")) == s5);
|
||||
CHECK(String64(STR(" 18446744073709551615")) == s5);
|
||||
|
||||
// Minimum uworkspace_t value is 0.
|
||||
etl::u32string<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::min(), s6, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u32string<64>(STR(" 0")) == s6);
|
||||
CHECK(String64(STR(" 0")) == s6);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -640,30 +642,48 @@ namespace
|
||||
{
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
etl::u32string<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u32string<64>(STR(" nan")) == s1);
|
||||
CHECK(String64(STR(" nan")) == s1);
|
||||
|
||||
etl::u32string<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u32string<64>(STR(" inf")) == s2);
|
||||
CHECK(String64(STR(" inf")) == s2);
|
||||
|
||||
etl::u32string<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u32string<64>(STR(" -inf")) == s3);
|
||||
CHECK(String64(STR(" -inf")) == s3);
|
||||
|
||||
etl::u32string<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u32string<64>(STR(" NAN")) == s4);
|
||||
CHECK(String64(STR(" NAN")) == s4);
|
||||
|
||||
etl::u32string<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u32string<64>(STR(" INF")) == s5);
|
||||
CHECK(String64(STR(" INF")) == s5);
|
||||
|
||||
etl::u32string<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u32string<64>(STR(" -INF")) == s6);
|
||||
CHECK(String64(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_1593_to_string_float_uses_double_math)
|
||||
{
|
||||
String64 s1;
|
||||
|
||||
// Float
|
||||
etl::to_string(3.1415927f, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Double
|
||||
etl::to_string(3.1415927, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Long double
|
||||
etl::to_string(3.1415927l, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -43,32 +43,35 @@ namespace
|
||||
{
|
||||
typedef etl::u8format_spec Format;
|
||||
|
||||
using String20 = etl::u8string<20>;
|
||||
using String64 = etl::u8string<64>;
|
||||
|
||||
SUITE(test_to_u8string)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_default_format_no_append)
|
||||
{
|
||||
etl::u8string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u8string<20>(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(etl::u8string<20>(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(etl::u8string<20>(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(etl::u8string<20>(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(etl::u8string<20>(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
CHECK(etl::u8string<20>(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str));
|
||||
CHECK(etl::u8string<20>(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str));
|
||||
CHECK(String20(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(String20(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
CHECK(String20(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str));
|
||||
CHECK(String20(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(etl::u8string<20>(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(etl::u8string<20>(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(etl::u8string<20>(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
CHECK(String20(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(String20(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(String20(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(String20(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(etl::u8string<20>(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(etl::u8string<20>(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(etl::u8string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
CHECK(String20(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(String20(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(String20(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -106,88 +109,87 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_format_right_justified_no_append)
|
||||
{
|
||||
etl::u8string<20> str;
|
||||
String20 str;
|
||||
|
||||
Format format = Format().base(10).width(20).fill(STR('#'));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("###################0")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(etl::u8string<20>(STR("###################0")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(etl::u8string<20>(STR("###################0")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(etl::u8string<20>(STR("###################0")) == etl::to_string(uint64_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::u8string<20>(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(etl::u8string<20>(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(etl::u8string<20>(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
CHECK(String20(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::u8string<20>(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::u8string<20>(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::u8string<20>(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::u8string<20>(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::u8string<20>(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::u8string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_format_left_justified_no_append)
|
||||
{
|
||||
etl::u8string<20> str;
|
||||
String20 str;
|
||||
|
||||
Format format = Format().base(10).width(20).fill(STR('#')).left();
|
||||
|
||||
CHECK(etl::u8string<20>(STR("0###################")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(etl::u8string<20>(STR("0###################")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(etl::u8string<20>(STR("0###################")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(etl::u8string<20>(STR("0###################")) == etl::to_string(uint64_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::u8string<20>(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(etl::u8string<20>(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(etl::u8string<20>(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
CHECK(String20(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::u8string<20>(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::u8string<20>(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::u8string<20>(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::u8string<20>(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::u8string<20>(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::u8string<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_binary_format_no_append)
|
||||
{
|
||||
etl::u8string<64> str;
|
||||
String64 str;
|
||||
|
||||
CHECK(etl::u8string<64>(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("00000000000000000000000000000000"))
|
||||
== etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("0000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::u8string<64>(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("10000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000"))
|
||||
== etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(uint64_t(9223372036854775808ull), str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::u8string<64>(STR("01111111")) == etl::to_string(INT8_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
CHECK(String64(STR("01111111")) == etl::to_string(INT8_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
== etl::to_string(INT64_MAX, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::u8string<64>(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::u8string<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(INT64_MIN, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
}
|
||||
|
||||
@ -259,328 +261,328 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::u8string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u8string<20>(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u8string<20>(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u8string<20>(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u8string<20>(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u8string<20>(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(etl::u8string<20>(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
CHECK(String20(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(String20(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::u8string<20>(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::u8string<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
CHECK(String20(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
CHECK(String20(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
CHECK(String20(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_rounding)
|
||||
{
|
||||
etl::u8string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u8string<20>(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(etl::u8string<20>(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(etl::u8string<20>(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(etl::u8string<20>(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(etl::u8string<20>(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::u8string<20>(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::u8string<20>(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::u8string<20>(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::u8string<20>(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(etl::u8string<20>(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(String20(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(String20(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(String20(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(String20(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::u8string<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::u8string<20>(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::u8string<20>(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(etl::u8string<20>(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::u8string<20>(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::u8string<20>(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(etl::u8string<20>(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::u8string<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::u8string<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_default_format)
|
||||
{
|
||||
etl::u8string<20> result;
|
||||
int value = -1234567;
|
||||
String20 result;
|
||||
int value = -1234567;
|
||||
|
||||
etl::to_string(value, 6U, result);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-1")) == result);
|
||||
CHECK(String20(STR("-1")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision)
|
||||
{
|
||||
etl::u8string<20> result;
|
||||
int value = -1234560;
|
||||
String20 result;
|
||||
int value = -1234560;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 6U, result, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-1.234560")) == result);
|
||||
CHECK(String20(STR("-1.234560")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision_64bit)
|
||||
{
|
||||
etl::u8string<20> result;
|
||||
int64_t value = INT64_MIN;
|
||||
String20 result;
|
||||
int64_t value = INT64_MIN;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 12U, result, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-9223372.036854775808")) == result);
|
||||
CHECK(String20(STR("-9223372.036854775808")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_fractional)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = -1000000;
|
||||
String20 result_i;
|
||||
int value_i = -1000000;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -1.000000;
|
||||
String20 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::u8string<20>(STR("-1.0000")) == result_i);
|
||||
CHECK(String20(STR("-1.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_value)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = 0;
|
||||
String20 result_i;
|
||||
int value_i = 0;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -0.000000;
|
||||
String20 result_d;
|
||||
double value_d = -0.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::u8string<20>(STR("0.0000")) == result_i);
|
||||
CHECK(String20(STR("0.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_integral_small_fractional)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = -400;
|
||||
String20 result_i;
|
||||
int value_i = -400;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -0.000400;
|
||||
String20 result_d;
|
||||
double value_d = -0.000400;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
etl::to_string(value_i, 6U, result_i, format);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-0.0004")) == result_i);
|
||||
CHECK(String20(STR("-0.0004")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_small_fractional)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = -123000400;
|
||||
String20 result_i;
|
||||
int value_i = -123000400;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -123.000400;
|
||||
String20 result_d;
|
||||
double value_d = -123.000400;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
etl::to_string(value_i, 6U, result_i, format);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-123.0004")) == result_i);
|
||||
CHECK(String20(STR("-123.0004")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_very_small_fractional)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = -123000004;
|
||||
String20 result_i;
|
||||
int value_i = -123000004;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -123.000004;
|
||||
String20 result_d;
|
||||
double value_d = -123.000004;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
etl::to_string(value_i, 6U, result_i, format);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-123.0000")) == result_i);
|
||||
CHECK(String20(STR("-123.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_very_small_fractional_rounded_up)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = -123000050;
|
||||
String20 result_i;
|
||||
int value_i = -123000050;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -123.000050;
|
||||
String20 result_d;
|
||||
double value_d = -123.000050;
|
||||
|
||||
Format format = Format().precision(4);
|
||||
|
||||
etl::to_string(value_i, 6U, result_i, format);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-123.0001")) == result_i);
|
||||
CHECK(String20(STR("-123.0001")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_shorter_width)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = -123456780;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(6).right();
|
||||
|
||||
etl::to_string(value_i, 6U, result_i, format);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-123.4568")) == result_i);
|
||||
CHECK(String20(STR("-123.4568")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_larger_width)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = -123456780;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(15).right();
|
||||
|
||||
etl::to_string(value_i, 6U, result_i, format);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR(" -123.4568")) == result_i);
|
||||
CHECK(String20(STR(" -123.4568")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_positive_rollover)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = 123999990;
|
||||
String20 result_i;
|
||||
int value_i = 123999990;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = 123.999990;
|
||||
String20 result_d;
|
||||
double value_d = 123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
etl::to_string(value_i, 6U, result_i, format);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("124.0000")) == result_i);
|
||||
CHECK(String20(STR("124.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_negative_rollover)
|
||||
{
|
||||
etl::u8string<20> result_i;
|
||||
int value_i = -123999990;
|
||||
String20 result_i;
|
||||
int value_i = -123999990;
|
||||
|
||||
etl::u8string<20> result_d;
|
||||
double value_d = -123.999990;
|
||||
String20 result_d;
|
||||
double value_d = -123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
etl::to_string(value_i, 6U, result_i, format);
|
||||
etl::to_string(value_d, result_d, format);
|
||||
|
||||
CHECK(etl::u8string<20>(STR("-124.0000")) == result_i);
|
||||
CHECK(String20(STR("-124.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
@ -590,48 +592,48 @@ namespace
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
// Check forced scientific formatting for smaller numbers.
|
||||
etl::u8string<64> s0;
|
||||
String64 s0;
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true));
|
||||
CHECK(etl::u8string<64>(STR(" 1.00000e+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000e+3")) == s0);
|
||||
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u8string<64>(STR(" 1.00000E+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000E+3")) == s0);
|
||||
|
||||
// Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision.
|
||||
etl::u8string<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::max(), s1, Format().precision(5).width(15).right());
|
||||
CHECK(etl::u8string<64>(STR(" 1.79769e+308")) == s1);
|
||||
CHECK(String64(STR(" 1.79769e+308")) == s1);
|
||||
|
||||
// Negative maximum double value is -1.7976931348623157e+308, which rounds to -1.79769e+308 with 5 digits of precision.
|
||||
etl::u8string<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(-std::numeric_limits<double>::max(), s2, Format().precision(5).width(15).right());
|
||||
CHECK(etl::u8string<64>(STR(" -1.79769e+308")) == s2);
|
||||
CHECK(String64(STR(" -1.79769e+308")) == s2);
|
||||
}
|
||||
|
||||
#if ETL_USING_64BIT_TYPES
|
||||
using workspace_t = etl::private_to_string::workspace_t;
|
||||
|
||||
// Maximum workspace_t value is 9223372036854775807.
|
||||
etl::u8string<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::max(), s3, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u8string<64>(STR(" 9223372036854775807")) == s3);
|
||||
CHECK(String64(STR(" 9223372036854775807")) == s3);
|
||||
|
||||
// Minimum workspace_t value is -9223372036854775808.
|
||||
etl::u8string<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::min(), s4, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u8string<64>(STR(" -9223372036854775808")) == s4);
|
||||
CHECK(String64(STR(" -9223372036854775808")) == s4);
|
||||
|
||||
using uworkspace_t = etl::private_to_string::uworkspace_t;
|
||||
|
||||
// Maximum uworkspace_t value is 18446744073709551615.
|
||||
etl::u8string<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::max(), s5, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u8string<64>(STR(" 18446744073709551615")) == s5);
|
||||
CHECK(String64(STR(" 18446744073709551615")) == s5);
|
||||
|
||||
// Minimum uworkspace_t value is 0.
|
||||
etl::u8string<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::min(), s6, Format().precision(5).width(21).right());
|
||||
CHECK(etl::u8string<64>(STR(" 0")) == s6);
|
||||
CHECK(String64(STR(" 0")) == s6);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -640,31 +642,49 @@ namespace
|
||||
{
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
etl::u8string<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u8string<64>(STR(" nan")) == s1);
|
||||
CHECK(String64(STR(" nan")) == s1);
|
||||
|
||||
etl::u8string<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u8string<64>(STR(" inf")) == s2);
|
||||
CHECK(String64(STR(" inf")) == s2);
|
||||
|
||||
etl::u8string<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::u8string<64>(STR(" -inf")) == s3);
|
||||
CHECK(String64(STR(" -inf")) == s3);
|
||||
|
||||
etl::u8string<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u8string<64>(STR(" NAN")) == s4);
|
||||
CHECK(String64(STR(" NAN")) == s4);
|
||||
|
||||
etl::u8string<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u8string<64>(STR(" INF")) == s5);
|
||||
CHECK(String64(STR(" INF")) == s5);
|
||||
|
||||
etl::u8string<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::u8string<64>(STR(" -INF")) == s6);
|
||||
CHECK(String64(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_1593_to_string_float_uses_double_math)
|
||||
{
|
||||
String64 s1;
|
||||
|
||||
// Float
|
||||
etl::to_string(3.1415927f, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Double
|
||||
etl::to_string(3.1415927, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Long double
|
||||
etl::to_string(3.1415927l, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@ -44,32 +44,35 @@ namespace
|
||||
{
|
||||
typedef etl::wformat_spec Format;
|
||||
|
||||
using String20 = etl::wstring<20>;
|
||||
using String64 = etl::wstring<64>;
|
||||
|
||||
SUITE(test_to_wstring)
|
||||
{
|
||||
//*************************************************************************
|
||||
TEST(test_default_format_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::wstring<20>(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(etl::wstring<20>(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(etl::wstring<20>(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(etl::wstring<20>(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint8_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint16_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint32_t(0), str));
|
||||
CHECK(String20(STR("0")) == etl::to_string(uint64_t(0), str));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(etl::wstring<20>(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
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(String20(STR("128")) == etl::to_string(uint8_t(128), str));
|
||||
CHECK(String20(STR("32768")) == etl::to_string(uint16_t(32768), str));
|
||||
CHECK(String20(STR("2147483648")) == etl::to_string(uint32_t(2147483648ul), str));
|
||||
CHECK(String20(STR("9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(etl::wstring<20>(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(etl::wstring<20>(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(etl::wstring<20>(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
CHECK(String20(STR("127")) == etl::to_string(INT8_MAX, str));
|
||||
CHECK(String20(STR("32767")) == etl::to_string(INT16_MAX, str));
|
||||
CHECK(String20(STR("2147483647")) == etl::to_string(INT32_MAX, str));
|
||||
CHECK(String20(STR("9223372036854775807")) == etl::to_string(INT64_MAX, str));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(etl::wstring<20>(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(etl::wstring<20>(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
CHECK(String20(STR("-128")) == etl::to_string(INT8_MIN, str));
|
||||
CHECK(String20(STR("-32768")) == etl::to_string(INT16_MIN, str));
|
||||
CHECK(String20(STR("-2147483648")) == etl::to_string(INT32_MIN, str));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -107,87 +110,87 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_format_right_justified_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
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(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));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("###################0")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::wstring<20>(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
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(String20(STR("#################128")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("###############32768")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("##########2147483648")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("#9223372036854775808")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::wstring<20>(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::wstring<20>(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::wstring<20>(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("#################127")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("###############32767")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("##########2147483647")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("#9223372036854775807")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::wstring<20>(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::wstring<20>(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("################-128")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("##############-32768")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("#########-2147483648")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_format_left_justified_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
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(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));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint8_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint16_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint32_t(0), str, format));
|
||||
CHECK(String20(STR("0###################")) == etl::to_string(uint64_t(0), str, format));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(etl::wstring<20>(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
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(String20(STR("128#################")) == etl::to_string(uint8_t(128), str, format));
|
||||
CHECK(String20(STR("32768###############")) == etl::to_string(uint16_t(32768), str, format));
|
||||
CHECK(String20(STR("2147483648##########")) == etl::to_string(uint32_t(2147483648ul), str, format));
|
||||
CHECK(String20(STR("9223372036854775808#")) == etl::to_string(uint64_t(9223372036854775808ull), str, format));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(etl::wstring<20>(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(etl::wstring<20>(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(etl::wstring<20>(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
CHECK(String20(STR("127#################")) == etl::to_string(INT8_MAX, str, format));
|
||||
CHECK(String20(STR("32767###############")) == etl::to_string(INT16_MAX, str, format));
|
||||
CHECK(String20(STR("2147483647##########")) == etl::to_string(INT32_MAX, str, format));
|
||||
CHECK(String20(STR("9223372036854775807#")) == etl::to_string(INT64_MAX, str, format));
|
||||
|
||||
CHECK(etl::wstring<20>(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(etl::wstring<20>(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(etl::wstring<20>(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(etl::wstring<20>(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
CHECK(String20(STR("-128################")) == etl::to_string(INT8_MIN, str, format));
|
||||
CHECK(String20(STR("-32768##############")) == etl::to_string(INT16_MIN, str, format));
|
||||
CHECK(String20(STR("-2147483648#########")) == etl::to_string(INT32_MIN, str, format));
|
||||
CHECK(String20(STR("-9223372036854775808")) == etl::to_string(INT64_MIN, str, format));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_binary_format_no_append)
|
||||
{
|
||||
etl::wstring<64> str;
|
||||
String64 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("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"))
|
||||
CHECK(String64(STR("00000000")) == etl::to_string(uint8_t(0), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000")) == etl::to_string(uint16_t(0), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("00000000000000000000000000000000")) == etl::to_string(uint32_t(0), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(uint64_t(0), str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::wstring<64>(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("10000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(uint8_t(128), str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(uint16_t(32768), str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000"))
|
||||
== etl::to_string(uint32_t(2147483648ul), str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(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_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
CHECK(String64(STR("01111111")) == etl::to_string(INT8_MAX, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111")) == etl::to_string(INT16_MAX, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("01111111111111111111111111111111")) == etl::to_string(INT32_MAX, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("0111111111111111111111111111111111111111111111111111111111111111"))
|
||||
== etl::to_string(INT64_MAX, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
|
||||
CHECK(etl::wstring<64>(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(etl::wstring<64>(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
CHECK(String64(STR("10000000")) == etl::to_string(INT8_MIN, str, Format().base(2).width(8).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000")) == etl::to_string(INT16_MIN, str, Format().base(2).width(16).fill(STR('0'))));
|
||||
CHECK(String64(STR("10000000000000000000000000000000")) == etl::to_string(INT32_MIN, str, Format().base(2).width(32).fill(STR('0'))));
|
||||
CHECK(String64(STR("1000000000000000000000000000000000000000000000000000000000000000"))
|
||||
== etl::to_string(INT64_MIN, str, Format().base(2).width(64).fill(STR('0'))));
|
||||
}
|
||||
|
||||
@ -259,119 +262,119 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::wstring<20>(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000000")) == etl::to_string(0.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000000 ")) == etl::to_string(0.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::wstring<20>(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 0.000001")) == etl::to_string(0.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("0.000001 ")) == etl::to_string(0.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::wstring<20>(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000000")) == etl::to_string(1.0, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000000 ")) == etl::to_string(1.0, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::wstring<20>(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 1.000001")) == etl::to_string(1.000001, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("1.000001 ")) == etl::to_string(1.000001, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::wstring<20>(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left()));
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(etl::wstring<20>(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
CHECK(String20(STR(" -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right()));
|
||||
CHECK(String20(STR("-12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left()));
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(etl::wstring<20>(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left()));
|
||||
CHECK(String20(STR(" -0.123456")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).right()));
|
||||
CHECK(String20(STR("-0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
CHECK(String20(STR("Result 12.345678")) == etl::to_string(12.345678, str, Format().precision(6).width(10).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result 12.345678 ")) == etl::to_string(12.345678, str, Format().precision(6).width(10).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
CHECK(String20(STR("Result -12.345678")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).right(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
CHECK(String20(STR("Result -12.345678 ")) == etl::to_string(-12.345678, str, Format().precision(6).width(11).left(), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
CHECK(String20(STR("Result -0.123456 ")) == etl::to_string(-0.123456, str, Format().precision(6).width(10).left(), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_floating_point_rounding)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::wstring<20>(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(etl::wstring<20>(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(etl::wstring<20>(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(etl::wstring<20>(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(etl::wstring<20>(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::wstring<20>(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(etl::wstring<20>(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::wstring<20>(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(etl::wstring<20>(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(etl::wstring<20>(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(etl::wstring<20>(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("0.00001")) == etl::to_string(0.000009, str, Format().precision(5).width(7).right()));
|
||||
CHECK(String20(STR("0.0001")) == etl::to_string(0.000099, str, Format().precision(4).width(6).right()));
|
||||
CHECK(String20(STR("0.001")) == etl::to_string(0.000999, str, Format().precision(3).width(5).right()));
|
||||
CHECK(String20(STR("0.01")) == etl::to_string(0.009999, str, Format().precision(2).width(4).right()));
|
||||
CHECK(String20(STR("0.1")) == etl::to_string(0.099999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1.0")) == etl::to_string(0.999999, str, Format().precision(1).width(3).right()));
|
||||
CHECK(String20(STR("1")) == etl::to_string(0.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("2")) == etl::to_string(1.999999, str, Format().precision(0).width(1).right()));
|
||||
CHECK(String20(STR("10.0")) == etl::to_string(9.999999, str, Format().precision(1).width(4).right()));
|
||||
CHECK(String20(STR("20.0")) == etl::to_string(19.999999, str, Format().precision(1).width(4).right()));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::wstring<20>(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(etl::wstring<20>(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(etl::wstring<20>(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR(" 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR(" 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false)));
|
||||
CHECK(String20(STR("0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
CHECK(String20(STR("1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false)));
|
||||
|
||||
CHECK(etl::wstring<20>(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::wstring<20>(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(etl::wstring<20>(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(etl::wstring<20>(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR(" false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR(" true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true)));
|
||||
CHECK(String20(STR("false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
CHECK(String20(STR("true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true)));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_bool_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 0 ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
CHECK(String20(STR("Result 1 ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(false), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false")) == to_string(false, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result true")) == to_string(true, str, Format().precision(6).width(10).right().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result false ")) == to_string(false, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
|
||||
str.assign(STR("Result "));
|
||||
CHECK(etl::wstring<20>(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
CHECK(String20(STR("Result true ")) == to_string(true, str, Format().precision(6).width(10).left().boolalpha(true), true));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_no_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
static const volatile int cvi = 0;
|
||||
|
||||
@ -379,8 +382,8 @@ namespace
|
||||
oss.width(10);
|
||||
oss.fill(STR('0'));
|
||||
oss << std::hex << std::right << uintptr_t(&cvi);
|
||||
std::wstring temp(oss.str());
|
||||
etl::wstring<20> compare(temp.begin(), temp.end());
|
||||
std::wstring temp(oss.str());
|
||||
String20 compare(temp.begin(), temp.end());
|
||||
|
||||
to_string(&cvi, str, Format().hex().width(10).right().fill(STR('0')));
|
||||
CHECK(compare == str);
|
||||
@ -400,7 +403,7 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_append)
|
||||
{
|
||||
etl::wstring<20> str;
|
||||
String20 str;
|
||||
|
||||
static const volatile int cvi = 0;
|
||||
|
||||
@ -410,7 +413,7 @@ namespace
|
||||
oss << std::hex << std::right << uintptr_t(&cvi);
|
||||
std::wstring temp(STR("Result "));
|
||||
temp.append(oss.str());
|
||||
etl::wstring<20> compare(temp.begin(), temp.end());
|
||||
String20 compare(temp.begin(), temp.end());
|
||||
|
||||
str.assign(STR("Result "));
|
||||
to_string(&cvi, str, Format().hex().width(10).right().fill(STR('0')), true);
|
||||
@ -433,217 +436,217 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_default_format)
|
||||
{
|
||||
etl::wstring<20> result;
|
||||
int value = -1234567;
|
||||
String20 result;
|
||||
int value = -1234567;
|
||||
|
||||
etl::to_string(value, 6U, result);
|
||||
|
||||
CHECK(etl::wstring<20>(STR("-1")) == result);
|
||||
CHECK(String20(STR("-1")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision)
|
||||
{
|
||||
etl::wstring<20> result;
|
||||
int value = -1234560;
|
||||
String20 result;
|
||||
int value = -1234560;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 6U, result, format);
|
||||
|
||||
CHECK(etl::wstring<20>(STR("-1.234560")) == result);
|
||||
CHECK(String20(STR("-1.234560")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_huge_precision_64bit)
|
||||
{
|
||||
etl::wstring<20> result;
|
||||
int64_t value = INT64_MIN;
|
||||
String20 result;
|
||||
int64_t value = INT64_MIN;
|
||||
|
||||
Format format = Format().precision(100);
|
||||
|
||||
etl::to_string(value, 12U, result, format);
|
||||
|
||||
CHECK(etl::wstring<20>(STR("-9223372.036854775808")) == result);
|
||||
CHECK(String20(STR("-9223372.036854775808")) == result);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_fractional)
|
||||
{
|
||||
etl::wstring<20> result_i;
|
||||
int value_i = -1000000;
|
||||
String20 result_i;
|
||||
int value_i = -1000000;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -1.000000;
|
||||
String20 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(String20(STR("-1.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_value)
|
||||
{
|
||||
etl::wstring<20> result_i;
|
||||
int value_i = 0;
|
||||
String20 result_i;
|
||||
int value_i = 0;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -0.000000;
|
||||
String20 result_d;
|
||||
double value_d = -0.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("0.0000")) == result_i);
|
||||
CHECK(String20(STR("0.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_integer_denominator_zero_integral_small_fractional)
|
||||
{
|
||||
etl::wstring<20> result_i;
|
||||
int value_i = -400;
|
||||
String20 result_i;
|
||||
int value_i = -400;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -0.000400;
|
||||
String20 result_d;
|
||||
double value_d = -0.000400;
|
||||
|
||||
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("-0.0004")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000400;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -123.000400;
|
||||
String20 result_d;
|
||||
double value_d = -123.000400;
|
||||
|
||||
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("-123.0004")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000004;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -123.000004;
|
||||
String20 result_d;
|
||||
double value_d = -123.000004;
|
||||
|
||||
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("-123.0000")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123000050;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -123.000050;
|
||||
String20 result_d;
|
||||
double value_d = -123.000050;
|
||||
|
||||
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("-123.0001")) == result_i);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(6).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123456780;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -123.456780;
|
||||
String20 result_d;
|
||||
double value_d = -123.456780;
|
||||
|
||||
Format format = Format().precision(4).width(15).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = 123999990;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = 123.999990;
|
||||
String20 result_d;
|
||||
double value_d = 123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(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;
|
||||
String20 result_i;
|
||||
int value_i = -123999990;
|
||||
|
||||
etl::wstring<20> result_d;
|
||||
double value_d = -123.999990;
|
||||
String20 result_d;
|
||||
double value_d = -123.999990;
|
||||
|
||||
Format format = Format().precision(4).right();
|
||||
|
||||
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);
|
||||
CHECK(String20(STR("-124.0000")) == result_i);
|
||||
CHECK(result_d == result_i);
|
||||
}
|
||||
|
||||
@ -653,48 +656,48 @@ namespace
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
// Check forced scientific formatting for smaller numbers.
|
||||
etl::wstring<64> s0;
|
||||
String64 s0;
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true));
|
||||
CHECK(etl::wstring<64>(STR(" 1.00000e+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000e+3")) == s0);
|
||||
|
||||
etl::to_string(1000.0, s0, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::wstring<64>(STR(" 1.00000E+3")) == s0);
|
||||
CHECK(String64(STR(" 1.00000E+3")) == s0);
|
||||
|
||||
// Maximum double value is 1.7976931348623157e+308, which rounds to 1.79769e+308 with 5 digits of precision.
|
||||
etl::wstring<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::max(), s1, Format().precision(5).width(15).right());
|
||||
CHECK(etl::wstring<64>(STR(" 1.79769e+308")) == s1);
|
||||
CHECK(String64(STR(" 1.79769e+308")) == s1);
|
||||
|
||||
// Negative maximum double value is -1.7976931348623157e+308, which rounds to -1.79769e+308 with 5 digits of precision.
|
||||
etl::wstring<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(-std::numeric_limits<double>::max(), s2, Format().precision(5).width(15).right());
|
||||
CHECK(etl::wstring<64>(STR(" -1.79769e+308")) == s2);
|
||||
CHECK(String64(STR(" -1.79769e+308")) == s2);
|
||||
}
|
||||
|
||||
#if ETL_USING_64BIT_TYPES
|
||||
using workspace_t = etl::private_to_string::workspace_t;
|
||||
|
||||
// Maximum workspace_t value is 9223372036854775807.
|
||||
etl::wstring<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::max(), s3, Format().precision(5).width(21).right());
|
||||
CHECK(etl::wstring<64>(STR(" 9223372036854775807")) == s3);
|
||||
CHECK(String64(STR(" 9223372036854775807")) == s3);
|
||||
|
||||
// Minimum workspace_t value is -9223372036854775808.
|
||||
etl::wstring<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<workspace_t>::min(), s4, Format().precision(5).width(21).right());
|
||||
CHECK(etl::wstring<64>(STR(" -9223372036854775808")) == s4);
|
||||
CHECK(String64(STR(" -9223372036854775808")) == s4);
|
||||
|
||||
using uworkspace_t = etl::private_to_string::uworkspace_t;
|
||||
|
||||
// Maximum uworkspace_t value is 18446744073709551615.
|
||||
etl::wstring<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::max(), s5, Format().precision(5).width(21).right());
|
||||
CHECK(etl::wstring<64>(STR(" 18446744073709551615")) == s5);
|
||||
CHECK(String64(STR(" 18446744073709551615")) == s5);
|
||||
|
||||
// Minimum uworkspace_t value is 0.
|
||||
etl::wstring<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(std::numeric_limits<uworkspace_t>::min(), s6, Format().precision(5).width(21).right());
|
||||
CHECK(etl::wstring<64>(STR(" 0")) == s6);
|
||||
CHECK(String64(STR(" 0")) == s6);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -703,30 +706,48 @@ namespace
|
||||
{
|
||||
if (std::numeric_limits<double>::is_iec559)
|
||||
{
|
||||
etl::wstring<64> s1;
|
||||
String64 s1;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s1, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::wstring<64>(STR(" nan")) == s1);
|
||||
CHECK(String64(STR(" nan")) == s1);
|
||||
|
||||
etl::wstring<64> s2;
|
||||
String64 s2;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s2, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::wstring<64>(STR(" inf")) == s2);
|
||||
CHECK(String64(STR(" inf")) == s2);
|
||||
|
||||
etl::wstring<64> s3;
|
||||
String64 s3;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s3, Format().precision(5).width(15).right().scientific(true).upper_case(false));
|
||||
CHECK(etl::wstring<64>(STR(" -inf")) == s3);
|
||||
CHECK(String64(STR(" -inf")) == s3);
|
||||
|
||||
etl::wstring<64> s4;
|
||||
String64 s4;
|
||||
etl::to_string(std::numeric_limits<double>::quiet_NaN(), s4, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::wstring<64>(STR(" NAN")) == s4);
|
||||
CHECK(String64(STR(" NAN")) == s4);
|
||||
|
||||
etl::wstring<64> s5;
|
||||
String64 s5;
|
||||
etl::to_string(std::numeric_limits<double>::infinity(), s5, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::wstring<64>(STR(" INF")) == s5);
|
||||
CHECK(String64(STR(" INF")) == s5);
|
||||
|
||||
etl::wstring<64> s6;
|
||||
String64 s6;
|
||||
etl::to_string(-std::numeric_limits<double>::infinity(), s6, Format().precision(5).width(15).right().scientific(true).upper_case(true));
|
||||
CHECK(etl::wstring<64>(STR(" -INF")) == s6);
|
||||
CHECK(String64(STR(" -INF")) == s6);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_issue_1593_to_string_float_uses_double_math)
|
||||
{
|
||||
String64 s1;
|
||||
|
||||
// Float
|
||||
etl::to_string(3.1415927f, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Double
|
||||
etl::to_string(3.1415927, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
|
||||
// Long double
|
||||
etl::to_string(3.1415927l, s1, Format().precision(4));
|
||||
CHECK_TRUE(String64(STR("3.1416")) == s1);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -6304,7 +6304,26 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03 - No virtual messages|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\syntax_check\clamped_value.h.t.cpp" />
|
||||
<ClCompile Include="..\syntax_check\clamped_value.h.t.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual imessage|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++ 20 - No Tests|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++23 - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++23|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - No STL - Optimised -O2|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03 - No virtual messages|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++17 - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release MSVC C++20 - Optimised O2|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - No virtual messages|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++14 - No STL|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang C++20|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang C++20 - Optimised -O2|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\syntax_check\cyclic_value.h.t.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang C++20|Win32'">true</ExcludedFromBuild>
|
||||
@ -11807,4 +11826,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@ -4124,4 +4124,4 @@
|
||||
<Filter>Resource Files\Images</Filter>
|
||||
</Image>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
Loading…
x
Reference in New Issue
Block a user