Always inline grisu_gen_digits and disable grisu2 by default
This commit is contained in:
parent
791294d17b
commit
3487f1b9cd
@ -44,6 +44,10 @@
|
|||||||
# define FMT_CATCH(x) if (false)
|
# define FMT_CATCH(x) if (false)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FMT_ENABLE_GRISU2
|
||||||
|
# define FMT_ENABLE_GRISU2 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# pragma warning(push)
|
# pragma warning(push)
|
||||||
# pragma warning(disable : 4702) // unreachable code
|
# pragma warning(disable : 4702) // unreachable code
|
||||||
@ -783,8 +787,8 @@ enum result {
|
|||||||
// error: the size of the region (lower, upper) outside of which numbers
|
// error: the size of the region (lower, upper) outside of which numbers
|
||||||
// definitely do not round to value (Delta in Grisu3).
|
// definitely do not round to value (Delta in Grisu3).
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
digits::result grisu_gen_digits(fp value, uint64_t error, int& exp,
|
FMT_ALWAYS_INLINE digits::result grisu_gen_digits(fp value, uint64_t error,
|
||||||
Handler& handler) {
|
int& exp, Handler& handler) {
|
||||||
const fp one(1ull << -value.e, value.e);
|
const fp one(1ull << -value.e, value.e);
|
||||||
// The integral part of scaled value (p1 in Grisu) = value / one. It cannot be
|
// The integral part of scaled value (p1 in Grisu) = value / one. It cannot be
|
||||||
// zero because it contains a product of two 64-bit numbers with MSB set (due
|
// zero because it contains a product of two 64-bit numbers with MSB set (due
|
||||||
@ -1103,7 +1107,8 @@ bool grisu_format(Double value, buffer<char>& buf, int precision,
|
|||||||
assert(min_exp <= upper.e && upper.e <= -32);
|
assert(min_exp <= upper.e && upper.e <= -32);
|
||||||
auto result = digits::result();
|
auto result = digits::result();
|
||||||
int size = 0;
|
int size = 0;
|
||||||
if ((options & grisu_options::grisu2) != 0) {
|
if (const_check(FMT_ENABLE_GRISU2 &&
|
||||||
|
(options & grisu_options::grisu2) != 0)) {
|
||||||
++lower.f; // \tilde{M}^- + 1 ulp -> M^-_{\uparrow}.
|
++lower.f; // \tilde{M}^- + 1 ulp -> M^-_{\uparrow}.
|
||||||
--upper.f; // \tilde{M}^+ - 1 ulp -> M^+_{\downarrow}.
|
--upper.f; // \tilde{M}^+ - 1 ulp -> M^+_{\downarrow}.
|
||||||
grisu_shortest_handler<2> handler{buf.data(), 0, (upper - normalized).f};
|
grisu_shortest_handler<2> handler{buf.data(), 0, (upper - normalized).f};
|
||||||
|
@ -739,17 +739,14 @@ template <unsigned BITS, typename UInt> inline int count_digits(UInt n) {
|
|||||||
|
|
||||||
template <> int count_digits<4>(internal::fallback_uintptr n);
|
template <> int count_digits<4>(internal::fallback_uintptr n);
|
||||||
|
|
||||||
#if FMT_HAS_CPP_ATTRIBUTE(always_inline)
|
#if FMT_GCC_VERSION || FMT_CLANG_VERSION
|
||||||
# define FMT_ALWAYS_INLINE __attribute__((always_inline))
|
# define FMT_ALWAYS_INLINE inline __attribute__((always_inline))
|
||||||
#else
|
#else
|
||||||
# define FMT_ALWAYS_INLINE
|
# define FMT_ALWAYS_INLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename Handler>
|
|
||||||
inline char* lg(uint32_t n, Handler h) FMT_ALWAYS_INLINE;
|
|
||||||
|
|
||||||
// Computes g = floor(log10(n)) and calls h.on<g>(n);
|
// Computes g = floor(log10(n)) and calls h.on<g>(n);
|
||||||
template <typename Handler> inline char* lg(uint32_t n, Handler h) {
|
template <typename Handler> FMT_ALWAYS_INLINE char* lg(uint32_t n, Handler h) {
|
||||||
return n < 100 ? n < 10 ? h.template on<0>(n) : h.template on<1>(n)
|
return n < 100 ? n < 10 ? h.template on<0>(n) : h.template on<1>(n)
|
||||||
: n < 1000000
|
: n < 1000000
|
||||||
? n < 10000 ? n < 1000 ? h.template on<2>(n)
|
? n < 10000 ? n < 1000 ? h.template on<2>(n)
|
||||||
|
Loading…
Reference in New Issue
Block a user