diff --git a/include/etl/format.h b/include/etl/format.h index 3268f43b..7812f9ab 100644 --- a/include/etl/format.h +++ b/include/etl/format.h @@ -48,7 +48,9 @@ SOFTWARE. #include "variant.h" #include "visitor.h" +#if ETL_USING_FORMAT_FLOATING_POINT #include +#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 void format_floating_default(OutputIt& it, T value, const format_spec_t& spec) { @@ -1214,6 +1221,7 @@ namespace etl private_format::format_sequence(it, "."); private_format::format_plain_num(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 void format_floating_g(OutputIt& it, T value, const format_spec_t& spec) { @@ -1409,6 +1418,7 @@ namespace etl } } } +#endif template struct format_visitor @@ -1490,6 +1500,7 @@ namespace etl return it; } +#if ETL_USING_FORMAT_FLOATING_POINT template typename format_context::iterator format_aligned_floating(Float arg, format_context& fmt_ctx) { @@ -1534,6 +1545,7 @@ namespace etl private_format::fill(it, suffix_size, fmt_ctx.format_spec.fill); return it; } +#endif template 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 { @@ -2119,6 +2132,7 @@ namespace etl return private_format::format_aligned_floating(arg, fmt_ctx); } }; +#endif template<> struct formatter diff --git a/include/etl/platform.h b/include/etl/platform.h index 6db7c305..a1ae4029 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -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); diff --git a/test/test_format.cpp b/test/test_format.cpp index a6c25eab..3d3338fa 100644 --- a/test/test_format.cpp +++ b/test/test_format.cpp @@ -197,6 +197,7 @@ namespace CHECK_EQUAL("-6759414", test_format(s, "{}", static_cast(-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)