15 #ifndef RAPIDJSON_IEEE754_
16 #define RAPIDJSON_IEEE754_
18 #include "../rapidjson.h"
20 RAPIDJSON_NAMESPACE_BEGIN
26 Double(
double d) : d_(d) {}
27 Double(uint64_t u) : u_(u) {}
29 double Value()
const {
return d_; }
30 uint64_t Uint64Value()
const {
return u_; }
32 double NextPositiveDouble()
const {
34 return Double(u_ + 1).Value();
37 bool Sign()
const {
return (u_ & kSignMask) != 0; }
38 uint64_t Significand()
const {
return u_ & kSignificandMask; }
39 int Exponent()
const {
return static_cast<int>(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); }
41 bool IsNan()
const {
return (u_ & kExponentMask) == kExponentMask && Significand() != 0; }
42 bool IsInf()
const {
return (u_ & kExponentMask) == kExponentMask && Significand() == 0; }
43 bool IsNormal()
const {
return (u_ & kExponentMask) != 0 || Significand() == 0; }
44 bool IsZero()
const {
return (u_ & (kExponentMask | kSignificandMask)) == 0; }
46 uint64_t IntegerSignificand()
const {
return IsNormal() ? Significand() | kHiddenBit : Significand(); }
47 int IntegerExponent()
const {
return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; }
48 uint64_t ToBias()
const {
return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; }
50 static unsigned EffectiveSignificandSize(
int order) {
53 else if (order <= -1074)
56 return (
unsigned)order + 1074;
60 static const int kSignificandSize = 52;
61 static const int kExponentBias = 0x3FF;
62 static const int kDenormalExponent = 1 - kExponentBias;
75 RAPIDJSON_NAMESPACE_END
77 #endif // RAPIDJSON_IEEE754_
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:261
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:1758
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344