6 #ifndef _INC_cFloatDeco_H
7 #define _INC_cFloatDeco_H
27 static const double k_PowersOf10[9];
29 static const UINT32 k_Exp10[10];
31 static const UINT64 k_MANT_MASK_X =
CUINT64(00100000, 00000000);
38 : m_uMant(0), m_iExp2(0)
42 : m_uMant(uMan), m_iExp2(iExp2)
56 m_uMant = nMantSig + k_MANT_MASK_X;
57 m_iExp2 = iExpBiased - k_DpExponentBias;
62 m_iExp2 = 1 - k_DpExponentBias;
80 #if defined(_MSC_VER) && defined(_M_AMD64)
81 UINT64 l = _umul128(m_uMant, rhs.
m_uMant, &h);
82 if (l & (UINT64(1) << 63))
84 #elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__x86_64__)
85 unsigned __int128 p =
static_cast<unsigned __int128
>(m_uMant) *
static_cast<unsigned __int128
>(rhs.
m_uMant);
87 UINT64 l =
static_cast<UINT64
>(p);
88 if (l & (UINT64(1) << 63))
91 const UINT64 M32 = 0xFFFFFFFF;
92 const UINT64 a = m_uMant >> 32;
93 const UINT64 b = m_uMant & M32;
94 const UINT64 c = rhs.
m_uMant >> 32;
95 const UINT64 d = rhs.
m_uMant & M32;
96 const UINT64 ac = a * c;
97 const UINT64 bc = b * c;
98 const UINT64 ad = a * d;
99 const UINT64 bd = b * d;
100 UINT64 tmp = (bd >> 32) + (ad & M32) + (bc & M32);
102 h = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
113 return cFloatDeco(m_uMant << nBit, m_iExp2 - nBit);
127 double get_Double()
const
140 if (n < 10)
return 1;
141 if (n < 100)
return 2;
142 if (n < 1000)
return 3;
143 if (n < 10000)
return 4;
144 if (n < 100000)
return 5;
145 if (n < 1000000)
return 6;
146 if (n < 10000000)
return 7;
147 if (n < 100000000)
return 8;
148 if (n < 1000000000)
return 9;
153 static double GRAYCALL toDouble(UINT32 frac1, UINT32 frac2,
int nExp10);
155 static void GRAYCALL GrisuRound(
char* pszOut,
StrLen_t len, UINT64 delta, UINT64 rest, UINT64 ten_kappa, UINT64 wp_w);
156 static StrLen_t GRAYCALL Grisu2(
double dVal,
char* pszOut, OUT
int* pnExp10);
#define GRAYCORE_LINK
Definition: GrayCore.h:47
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define CUINT64(h, l)
Definition: cBits.h:39
#define ASSERT(exp)
Definition: cDebugAssert.h:87
cUnion64 m_v
holds the float64.
Definition: cFloat.h:89
static const UINT64 k_EXP_MASK
11 bits = signed exponent (base 2)
Definition: cFloat.h:93
UINT64 get_Mantissa() const noexcept
Definition: cFloat.h:140
static const UINT32 k_MANT_BITS
52 bits = fractional mantissa
Definition: cFloat.h:96
Definition: cFloatDeco.h:21
cFloatDeco(double d) noexcept
Definition: cFloatDeco.h:45
cFloatDeco operator-(const cFloatDeco &rhs) const
Definition: cFloatDeco.h:66
int m_iExp2
Hold base 2 Biased Exponent.
Definition: cFloatDeco.h:34
cFloatDeco(UINT64 uMan, int iExp2) noexcept
Definition: cFloatDeco.h:41
static unsigned GetCountDecimalDigit32(UINT32 n) noexcept
Definition: cFloatDeco.h:135
cFloatDeco operator*(const cFloatDeco &rhs) const
Definition: cFloatDeco.h:75
cFloatDeco() noexcept
Definition: cFloatDeco.h:37
UINT64 m_uMant
Hold Mantissa.
Definition: cFloatDeco.h:33
cFloatDeco Normalize() const
Definition: cFloatDeco.h:107
void NormalizedBoundaries(cFloatDeco *minus, cFloatDeco *plus) const
Definition: cFloatDeco.h:116
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
unsigned int BIT_ENUM_t
Enumerate number of bits or address a single bit in some array of bits.
Definition: cBits.h:20
static BIT_ENUM_t Highest1Bit(TYPE nMask) noexcept
Definition: cBits.h:108
UINT64 u_qw
64 bits = QuadPart = ULONGLONG.
Definition: cTypes.h:122