From bc654faf82e54d29f6c5fd7efcfd16a587917e82 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Tue, 15 Mar 2022 08:21:20 -0700 Subject: [PATCH] Add is_floating_point that works with __float128 --- include/fmt/format.h | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 08c94755..6ed53aa9 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -667,6 +667,17 @@ inline auto code_point_index(basic_string_view s, size_t n) return s.size(); } +#ifdef __SIZEOF_FLOAT128__ +using float128 = __float128; +#else +using float128 = void; +#endif +template using is_float128 = std::is_same; + +template +using is_floating_point = + bool_constant::value || is_float128::value>; + template ::value> struct is_fast_float : bool_constant::is_iec559 && sizeof(T) <= sizeof(double)> {}; @@ -935,7 +946,7 @@ FMT_CONSTEXPR auto is_negative(T) -> bool { return false; } -template ::value)> +template FMT_CONSTEXPR auto is_supported_floating_point(T) -> uint16_t { return (std::is_same::value && FMT_USE_FLOAT) || (std::is_same::value && FMT_USE_DOUBLE) || @@ -2157,13 +2168,6 @@ FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& fp, } } -#ifdef __SIZEOF_FLOAT128__ -using float128 = __float128; -#else -using float128 = void; -#endif -template using is_float128 = std::is_same; - template ::value && !is_float128::value)> FMT_CONSTEXPR20 bool isfinite(T value) { @@ -2179,7 +2183,7 @@ template constexpr bool isnan(T value) { return value != value; // std::isnan doesn't support __float128. } -template ::value)> +template ::value)> FMT_INLINE FMT_CONSTEXPR bool signbit(T value) { if (is_constant_evaluated()) { #ifdef __cpp_if_constexpr @@ -2193,7 +2197,7 @@ FMT_INLINE FMT_CONSTEXPR bool signbit(T value) { } template ::value)> + FMT_ENABLE_IF(is_floating_point::value)> FMT_CONSTEXPR20 auto write(OutputIt out, T value, basic_format_specs specs, locale_ref loc = {}) -> OutputIt { @@ -2271,7 +2275,7 @@ FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt { } template ::value && + FMT_ENABLE_IF(is_floating_point::value && !is_fast_float::value)> inline auto write(OutputIt out, T value) -> OutputIt { return write(out, value, basic_format_specs());