Code review updates

This commit is contained in:
John Wellbelove 2026-09-25 08:32:39 +01:00
parent e8be428b35
commit 72300a653d
8 changed files with 118 additions and 85 deletions

View File

@ -49,7 +49,7 @@ ETL_CONSTEXPR bool is_exactly_equal(T value1, T value2)
## floor
Defined in the `etl::clib` namespace.
Defined in the `etl::math` namespace.
---
@ -58,7 +58,7 @@ ETL_NODISCARD
float floor(float value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::floorf`.
A wrapper around `::floorf` in `<math.h>`.
**Returns**
`::floorf(value)`
@ -70,7 +70,7 @@ ETL_NODISCARD
double floor(double value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::floor`.
A wrapper around `::floor` in `<math.h>`.
**Returns**
`::floor(value)`
@ -82,7 +82,7 @@ ETL_NODISCARD
long double floor(long double value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::floorl`.
A wrapper around `::floorl` in `<math.h>`.
**Returns**
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
@ -92,7 +92,7 @@ otherwise
## ceil
Defined in the `etl::clib` namespace.
Defined in the `etl::math` namespace.
---
@ -101,7 +101,7 @@ ETL_NODISCARD
float ceil(float value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::ceilf`.
A wrapper around `::ceilf` in `<math.h>`.
**Returns**
`::ceilf(value)`
@ -113,7 +113,7 @@ ETL_NODISCARD
double ceil(double value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::ceil`.
A wrapper around `::ceil` in `<math.h>`.
**Returns**
`::ceil(value)`
@ -125,7 +125,7 @@ ETL_NODISCARD
long double ceil(long double value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::ceill`.
A wrapper around `::ceill` in `<math.h>`.
**Returns**
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
@ -135,7 +135,7 @@ otherwise
## log10
Defined in the `etl::clib` namespace.
Defined in the `etl::math` namespace.
---
@ -144,7 +144,7 @@ ETL_NODISCARD
float log10(float value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::log10f`.
A wrapper around `::log10f` in `<math.h>`.
**Returns**
`::log10f(value)`
@ -156,7 +156,7 @@ ETL_NODISCARD
double log10(double value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::log10`.
A wrapper around `::log10` in `<math.h>`.
**Returns**
`::log10(value)`
@ -168,7 +168,7 @@ ETL_NODISCARD
long double log10(long double value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::log10l`.
A wrapper around `::log10l` in `<math.h>`.
**Returns**
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
@ -178,7 +178,7 @@ otherwise
## round
Defined in the `etl::clib` namespace.
Defined in the `etl::math` namespace.
---
@ -187,7 +187,7 @@ ETL_NODISCARD
float round(float value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::roundf`.
A wrapper around `::roundf` in `<math.h>`.
**Returns**
`::roundf(value)`
@ -199,7 +199,7 @@ ETL_NODISCARD
double round(double value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::round`.
A wrapper around `::round` in `<math.h>`.
**Returns**
`::round(value)`
@ -211,7 +211,7 @@ ETL_NODISCARD
long double round(long double value) ETL_NOEXCEPT
```
**Description**
A wrapper around `::roundl`.
A wrapper around `::roundl` in `<math.h>`.
**Returns**
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
@ -221,7 +221,7 @@ otherwise
## pow
Defined in the `etl::clib` namespace.
Defined in the `etl::math` namespace.
---
@ -230,7 +230,7 @@ ETL_NODISCARD
float pow(float base, float exponent) ETL_NOEXCEPT
```
**Description**
A wrapper around `::powf`.
A wrapper around `::powf` in `<math.h>`.
**Returns**
`::powf(base, exponent)`
@ -242,7 +242,7 @@ ETL_NODISCARD
double pow(double base, double exponent) ETL_NOEXCEPT
```
**Description**
A wrapper around `::pow`.
A wrapper around `::pow` in `<math.h>`.
**Returns**
`::pow(base, exponent)`
@ -254,7 +254,7 @@ ETL_NODISCARD
long double pow(long double base, long double exponent) ETL_NOEXCEPT
```
**Description**
A wrapper around `::powl`.
A wrapper around `::powl` in `<math.h>`.
**Returns**
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns
@ -264,7 +264,7 @@ otherwise
## modf
Defined in the `etl::clib` namespace.
Defined in the `etl::math` namespace.
---
@ -273,7 +273,7 @@ ETL_NODISCARD
float modf(float value, float* intpart) ETL_NOEXCEPT
```
**Description**
A wrapper around `::modff`.
A wrapper around `::modff` in `<math.h>`.
**Returns**
`::modff(value, intpart)`
@ -285,7 +285,7 @@ ETL_NODISCARD
double modf(double value, double* intpart) ETL_NOEXCEPT
```
**Description**
A wrapper around `::modf`.
A wrapper around `::modf` in `<math.h>`.
**Returns**
`::modf(value, intpart)`
@ -297,7 +297,7 @@ ETL_NODISCARD
long double modf(long double value, long double* intpart) ETL_NOEXCEPT
```
**Description**
A wrapper around `::modfl`.
A wrapper around `::modfl` in `<math.h>`.
**Returns**
If `ETL_NO_LONG_DOUBLE_MATH` is defined then returns

View File

@ -1756,7 +1756,7 @@ namespace etl
}
T integral;
T fractional = etl::clib::modf(value, &integral);
T fractional = etl::math::modf(value, &integral);
// Take absolute values to avoid casting negative values to unsigned
if (sign)
@ -1766,7 +1766,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>(etl::clib::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)
@ -1793,20 +1793,20 @@ namespace etl
bool sign = signbit(value);
T integral;
T fractional = etl::clib::modf(value, &integral);
T fractional = etl::math::modf(value, &integral);
while (value >= 0x10 || value <= -0x10)
{
++exponent_int;
value /= 0x10;
fractional = etl::clib::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 = etl::clib::modf(value, &integral);
fractional = etl::math::modf(value, &integral);
}
// Take absolute values to avoid casting negative values to unsigned
@ -1817,7 +1817,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>(etl::clib::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)
@ -1861,8 +1861,8 @@ namespace etl
if (abs_value > static_cast<T>(0))
{
exponent_int = static_cast<long long int>(etl::clib::floor(etl::clib::log10(abs_value)));
value = abs_value / etl::clib::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))
{
@ -1881,10 +1881,10 @@ namespace etl
}
T integral;
T fractional = etl::clib::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>(etl::clib::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)
@ -1922,7 +1922,7 @@ namespace etl
bool sign = signbit(value);
T integral;
T fractional = etl::clib::modf(value, &integral);
T fractional = etl::math::modf(value, &integral);
// Take absolute values to avoid casting negative values to unsigned
if (sign)
@ -1932,7 +1932,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>(etl::clib::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)

View File

@ -133,14 +133,14 @@ namespace etl
#include "private/diagnostic_pop.h"
//***************************************************************************
// These functions wrap the C library math functions.
// 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 clib namespace to avoid conflicts with the C library and ETL functions.
// 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 clib
namespace math
{
//***************************************************************************
// floor
@ -296,7 +296,7 @@ namespace etl
#else
//*********************************
ETL_NODISCARD
inline long double power(long double base, long double exponent) ETL_NOEXCEPT
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)));
}
@ -305,14 +305,12 @@ namespace etl
//***************************************************************************
// modf
//***************************************************************************
ETL_NODISCARD
inline float modf(float value, float* intpart) ETL_NOEXCEPT
{
return ::modff(value, intpart);
}
//*********************************
ETL_NODISCARD
inline double modf(double value, double* intpart) ETL_NOEXCEPT
{
return ::modf(value, intpart);
@ -320,14 +318,12 @@ namespace etl
#if ETL_USING_LONG_DOUBLE_MATH
//*********************************
ETL_NODISCARD
inline long double modf(long double value, long double* intpart) ETL_NOEXCEPT
{
return ::modfl(value, intpart);
}
#else
//*********************************
ETL_NODISCARD
inline long double modf(long double value, long double* intpart) ETL_NOEXCEPT
{
double d_iptr;
@ -337,7 +333,7 @@ namespace etl
return static_cast<long double>(result);
}
#endif
} // namespace clib
} // namespace math
} // namespace etl
#endif

View File

@ -174,24 +174,12 @@ SOFTWARE.
#define ETL_NOT_USING_FORMAT_FLOATING_POINT 0
#endif
//*************************************
// Helper macro for ETL_FORMAT_NO_LONG_DOUBLE_MATH.
// Define ETL_FORMAT_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
#else
#define ETL_USING_FORMAT_LONG_DOUBLE_MATH 1
#define ETL_NOT_USING_FORMAT_LONG_DOUBLE_MATH 0
#endif
//*************************************
// 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.
// 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

View File

@ -345,11 +345,11 @@ namespace etl
}
// Find the integral part of the floating point
T f_integral = etl::clib::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>(etl::clib::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)
@ -402,7 +402,7 @@ namespace etl
}
// Find the integral part of the floating point
T f_integral = etl::clib::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.

View File

@ -141,12 +141,12 @@ namespace
long double ld1 = 1.7L;
long double ld2 = -1.7L;
CHECK_CLOSE(1.0f, etl::clib::floor(f1), 0.0001f);
CHECK_CLOSE(-2.0f, etl::clib::floor(f2), 0.0001f);
CHECK_CLOSE(1.0, etl::clib::floor(d1), 0.0001);
CHECK_CLOSE(-2.0, etl::clib::floor(d2), 0.0001);
CHECK_CLOSE(1.0L, etl::clib::floor(ld1), 0.0001L);
CHECK_CLOSE(-2.0L, etl::clib::floor(ld2), 0.0001L);
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);
}
//*************************************************************************
@ -159,12 +159,12 @@ namespace
long double ld1 = 1.2L;
long double ld2 = -1.2L;
CHECK_CLOSE(2.0f, etl::clib::ceil(f1), 0.0001f);
CHECK_CLOSE(-1.0f, etl::clib::ceil(f2), 0.0001f);
CHECK_CLOSE(2.0, etl::clib::ceil(d1), 0.0001);
CHECK_CLOSE(-1.0, etl::clib::ceil(d2), 0.0001);
CHECK_CLOSE(2.0L, etl::clib::ceil(ld1), 0.0001L);
CHECK_CLOSE(-1.0L, etl::clib::ceil(ld2), 0.0001L);
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);
}
//*************************************************************************
@ -174,9 +174,39 @@ namespace
double d1 = 1000.0;
long double ld1 = 10000.0L;
CHECK_CLOSE(2.0f, etl::clib::log10(f1), 0.0001f);
CHECK_CLOSE(3.0, etl::clib::log10(d1), 0.0001);
CHECK_CLOSE(4.0L, etl::clib::log10(ld1), 0.0001L);
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);
}
//*************************************************************************
@ -189,9 +219,9 @@ namespace
long double ldb = 2.0L;
long double lde = 4.0L;
CHECK_CLOSE(8.0f, etl::clib::pow(fb, fe), 0.0001f);
CHECK_CLOSE(1024.0, etl::clib::pow(db, de), 0.0001);
CHECK_CLOSE(16.0L, etl::clib::pow(ldb, lde), 0.0001L);
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);
}
//*************************************************************************
@ -204,9 +234,9 @@ namespace
long double ld1 = 3.75L;
long double ld_intpart = 0.0L;
float f_frac = etl::clib::modf(f1, &f_intpart);
double d_frac = etl::clib::modf(d1, &d_intpart);
long double ld_frac = etl::clib::modf(ld1, &ld_intpart);
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);

View File

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

View File

@ -4124,4 +4124,4 @@
<Filter>Resource Files\Images</Filter>
</Image>
</ItemGroup>
</Project>
</Project>