microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
debug_float.hpp File Reference

Opt-in reloco::Debug<T> specializations for float/double/ long double. More...

#include <cstddef>
#include <cstdio>
#include <microfmt/microfmt.hpp>
#include <type_traits>
Include dependency graph for debug_float.hpp:

Go to the source code of this file.

Classes

struct  reloco::Debug< float >
 Debug<float>: see this file's header comment. More...
 
struct  reloco::Debug< double >
 Debug<double>: see this file's header comment. More...
 
struct  reloco::Debug< long double >
 Debug<long double>: see this file's header comment. More...
 

Namespaces

namespace  reloco
 
namespace  reloco::detail
 

Functions

template<typename T >
RELOCO_BEGIN_UNSAFE_CODE void reloco::detail::format_debug_float (T val, const sink &out) noexcept
 Shared g/Lg-based implementation behind every Debug<float/double/long double>::format below.
 

Detailed Description

Opt-in reloco::Debug<T> specializations for float/double/ long double.

Deliberately not pulled in by formatters/std_debug.hpp (or any other header included by default): reloco/microfmt avoid floating point everywhere by default – formatters/floating.hpp's formatter<float>/ formatter<double>/formatter<long double> are already an explicit, separately-included opt-in for the same reason (kernel/bare-metal code frequently cannot use the FPU at all without extra save/restore ceremony). A consumer who has already opted into float support via floating.hpp includes this header too, deliberately, to also get {:?}/as_debug() support for those types.

Uses <cstdio>'s std::snprintf directly (no <iostream>, matching floating.hpp's own approach) into a fixed stack buffer – no heap allocation. Rust's f32/f64 Debug always shows a decimal point/ exponent even for whole-number values (1.0, not 1); g doesn't guarantee that (e.g. 1 for 1.0f), so a bare .0 is appended whenever the g output has neither a . nor an e/E exponent and isn't one of the inf/nan special values (which never take a trailing .0 either way).