mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Add ETL_FORMAT_NO_FLOATING_POINT control macro for etl::format (#1329)
When ETL_FORMAT_NO_FLOATING_POINT is defined, all floating-point formatting support (float, double, long double) is excluded from etl::format. This reduces code size on targets that do not require floating-point formatting. Guarded sections: - #include <cmath> - float/double/long double in supported_format_types variant - float/double/long double constructors in basic_format_arg - format_floating_* functions and format_aligned_floating - formatter<float>, formatter<double>, formatter<long double> - Floating-point test cases in test_format.cpp Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
This commit is contained in:
parent
f88b1514b7
commit
c162a96686
@ -48,7 +48,9 @@ SOFTWARE.
|
||||
#include "variant.h"
|
||||
#include "visitor.h"
|
||||
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
#include <cmath>
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
|
||||
@ -138,9 +140,11 @@ namespace etl
|
||||
unsigned int,
|
||||
long long int,
|
||||
unsigned long long int,
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
float,
|
||||
double,
|
||||
long double,
|
||||
#endif
|
||||
const char*,
|
||||
etl::string_view,
|
||||
const void*
|
||||
@ -302,6 +306,7 @@ namespace etl
|
||||
{
|
||||
}
|
||||
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
basic_format_arg(const float v)
|
||||
: data(v)
|
||||
{
|
||||
@ -316,6 +321,7 @@ namespace etl
|
||||
: data(v)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
basic_format_arg(const etl::string_view v)
|
||||
: data(v)
|
||||
@ -1039,6 +1045,7 @@ namespace etl
|
||||
format_plain_num(it, value, spec, width);
|
||||
}
|
||||
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
template<typename OutputIt, typename T>
|
||||
void format_floating_default(OutputIt& it, T value, const format_spec_t& spec)
|
||||
{
|
||||
@ -1214,6 +1221,7 @@ namespace etl
|
||||
private_format::format_sequence<OutputIt>(it, ".");
|
||||
private_format::format_plain_num<OutputIt, unsigned long long int>(it, fractional_int, spec, fractional_decimals);
|
||||
}
|
||||
#endif
|
||||
|
||||
class dummy_assign_to
|
||||
{
|
||||
@ -1336,6 +1344,7 @@ namespace etl
|
||||
size_t count;
|
||||
};
|
||||
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
template<typename OutputIt, typename T>
|
||||
void format_floating_g(OutputIt& it, T value, const format_spec_t& spec)
|
||||
{
|
||||
@ -1409,6 +1418,7 @@ namespace etl
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class OutputIt>
|
||||
struct format_visitor
|
||||
@ -1490,6 +1500,7 @@ namespace etl
|
||||
return it;
|
||||
}
|
||||
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
template<typename OutputIt, typename Float>
|
||||
typename format_context<OutputIt>::iterator format_aligned_floating(Float arg, format_context<OutputIt>& fmt_ctx)
|
||||
{
|
||||
@ -1534,6 +1545,7 @@ namespace etl
|
||||
private_format::fill<OutputIt>(it, suffix_size, fmt_ctx.format_spec.fill);
|
||||
return it;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<typename OutputIt>
|
||||
void format_string_view(OutputIt& it, etl::string_view arg, const format_spec_t& spec)
|
||||
@ -2072,6 +2084,7 @@ namespace etl
|
||||
}
|
||||
};
|
||||
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
template<>
|
||||
struct formatter<float>
|
||||
{
|
||||
@ -2119,6 +2132,7 @@ namespace etl
|
||||
return private_format::format_aligned_floating<OutputIt, long double>(arg, fmt_ctx);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template<>
|
||||
struct formatter<etl::string_view>
|
||||
|
||||
@ -154,6 +154,16 @@ SOFTWARE.
|
||||
#define ETL_NOT_USING_WIDE_CHARACTERS 0
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Helper macro for ETL_FORMAT_NO_FLOATING_POINT.
|
||||
#if defined(ETL_FORMAT_NO_FLOATING_POINT)
|
||||
#define ETL_USING_FORMAT_FLOATING_POINT 0
|
||||
#define ETL_NOT_USING_FORMAT_FLOATING_POINT 1
|
||||
#else
|
||||
#define ETL_USING_FORMAT_FLOATING_POINT 1
|
||||
#define ETL_NOT_USING_FORMAT_FLOATING_POINT 0
|
||||
#endif
|
||||
|
||||
//*************************************
|
||||
// Figure out things about the compiler, if haven't already done so in etl_profile.h
|
||||
#include "profiles/determine_compiler_version.h"
|
||||
@ -651,6 +661,7 @@ namespace etl
|
||||
static ETL_CONSTANT bool using_exceptions = (ETL_USING_EXCEPTIONS == 1);
|
||||
static ETL_CONSTANT bool using_libc_wchar_h = (ETL_USING_LIBC_WCHAR_H == 1);
|
||||
static ETL_CONSTANT bool using_std_exception = (ETL_USING_STD_EXCEPTION == 1);
|
||||
static ETL_CONSTANT bool using_format_floating_point = (ETL_USING_FORMAT_FLOATING_POINT == 1);
|
||||
|
||||
// Has...
|
||||
static ETL_CONSTANT bool has_initializer_list = (ETL_HAS_INITIALIZER_LIST == 1);
|
||||
|
||||
@ -197,6 +197,7 @@ namespace
|
||||
CHECK_EQUAL("-6759414", test_format(s, "{}", static_cast<int32_t>(-6759414)));
|
||||
}
|
||||
|
||||
#if ETL_USING_FORMAT_FLOATING_POINT
|
||||
//*************************************************************************
|
||||
TEST(test_format_float)
|
||||
{
|
||||
@ -266,6 +267,7 @@ namespace
|
||||
CHECK_EQUAL("0x1.92a738p-5", test_format(s, "{:a}", 0.0000015f));
|
||||
CHECK_EQUAL("0x1.6345785d8ap+e", test_format(s, "{:a}", 100000000000000000.l));
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_format_char_array)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user