45RELOCO_BEGIN_UNSAFE_CODE
49 if constexpr (std::is_same_v<T, long double>) {
50 written = std::snprintf(buf,
sizeof(buf),
"%Lg", val);
52 written = std::snprintf(buf,
sizeof(buf),
"%g",
static_cast<double>(val));
58 const std::size_t len =
59 static_cast<std::size_t
>(written) <
sizeof(buf) ?
static_cast<std::size_t
>(written) :
sizeof(buf) - 1;
60 const microfmt::string_view text(buf, len);
63 const bool has_dot_or_exp = text.find(
'.') != microfmt::string_view::npos ||
64 text.find(
'e') != microfmt::string_view::npos ||
65 text.find(
'E') != microfmt::string_view::npos;
66 const bool is_special =
67 text.find(
"inf") != microfmt::string_view::npos || text.find(
"nan") != microfmt::string_view::npos;
68 if (!has_dot_or_exp && !is_special) {
77template <>
struct Debug<float> {
78 static void format(
float val,
const sink &out)
noexcept { detail::format_debug_float(val, out); }
82template <>
struct Debug<double> {
83 static void format(
double val,
const sink &out)
noexcept { detail::format_debug_float(val, out); }
87template <>
struct Debug<long double> {
88 static void format(
long double val,
const sink &out)
noexcept { detail::format_debug_float(val, out); }
Core formatting primitives, sinks, and customization point.
RELOCO_BEGIN_UNSAFE_CODE void format_debug_float(T val, const sink &out) noexcept
Shared g/Lg-based implementation behind every Debug<float/double/long double>::format below.
Definition debug_float.hpp:46
Definition debug_float.hpp:36
static void format(double val, const sink &out) noexcept
Definition debug_float.hpp:83
static void format(float val, const sink &out) noexcept
Definition debug_float.hpp:78
static void format(long double val, const sink &out) noexcept
Definition debug_float.hpp:88