ieee754.h
Go to the documentation of this file.
1 // Tencent is pleased to support the open source community by making RapidJSON
2 // available.
3 //
4 // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All
5 // rights reserved.
6 //
7 // Licensed under the MIT License (the "License"); you may not use this file
8 // except in compliance with the License. You may obtain a copy of the License
9 // at
10 //
11 // http://opensource.org/licenses/MIT
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 // License for the specific language governing permissions and limitations under
17 // the License.
18 
19 #ifndef RAPIDJSON_IEEE754_
20 #define RAPIDJSON_IEEE754_
21 
22 #include "../rapidjson.h"
23 
25 namespace internal {
26 
27 class Double {
28  public:
29  Double() {}
30  Double(double d) : d_(d) {}
31  Double(uint64_t u) : u_(u) {}
32 
33  double Value() const { return d_; }
34  uint64_t Uint64Value() const { return u_; }
35 
36  double NextPositiveDouble() const {
38  return Double(u_ + 1).Value();
39  }
40 
41  bool Sign() const { return (u_ & kSignMask) != 0; }
42  uint64_t Significand() const { return u_ & kSignificandMask; }
43  int Exponent() const {
44  return static_cast<int>(((u_ & kExponentMask) >> kSignificandSize) -
46  }
47 
48  bool IsNan() const {
49  return (u_ & kExponentMask) == kExponentMask && Significand() != 0;
50  }
51  bool IsInf() const {
52  return (u_ & kExponentMask) == kExponentMask && Significand() == 0;
53  }
54  bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; }
55  bool IsNormal() const {
56  return (u_ & kExponentMask) != 0 || Significand() == 0;
57  }
58  bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; }
59 
61  return IsNormal() ? Significand() | kHiddenBit : Significand();
62  }
63  int IntegerExponent() const {
65  }
66  uint64_t ToBias() const {
67  return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask;
68  }
69 
70  static int EffectiveSignificandSize(int order) {
71  if (order >= -1021)
72  return 53;
73  else if (order <= -1074)
74  return 0;
75  else
76  return order + 1074;
77  }
78 
79  private:
80  static const int kSignificandSize = 52;
81  static const int kExponentBias = 0x3FF;
82  static const int kDenormalExponent = 1 - kExponentBias;
83  static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000);
84  static const uint64_t kExponentMask =
85  RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000);
86  static const uint64_t kSignificandMask =
87  RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
88  static const uint64_t kHiddenBit =
89  RAPIDJSON_UINT64_C2(0x00100000, 0x00000000);
90 
91  union {
92  double d_;
94  };
95 };
96 
97 } // namespace internal
99 
100 #endif // RAPIDJSON_IEEE754_
static const int kSignificandSize
Definition: ieee754.h:80
uint64_t u_
Definition: ieee754.h:93
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:433
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:306
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:131
Double(uint64_t u)
Definition: ieee754.h:31
static const uint64_t kExponentMask
Definition: ieee754.h:84
uint64_t Significand() const
Definition: ieee754.h:42
bool IsNanOrInf() const
Definition: ieee754.h:54
static int EffectiveSignificandSize(int order)
Definition: ieee754.h:70
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:128
static const uint64_t kSignMask
Definition: ieee754.h:83
Double(double d)
Definition: ieee754.h:30
double Value() const
Definition: ieee754.h:33
bool IsInf() const
Definition: ieee754.h:51
bool IsNormal() const
Definition: ieee754.h:55
bool Sign() const
Definition: ieee754.h:41
double NextPositiveDouble() const
Definition: ieee754.h:36
bool IsNan() const
Definition: ieee754.h:48
static const int kDenormalExponent
Definition: ieee754.h:82
bool IsZero() const
Definition: ieee754.h:58
unsigned __int64 uint64_t
Definition: stdint.h:137
uint64_t IntegerSignificand() const
Definition: ieee754.h:60
uint64_t Uint64Value() const
Definition: ieee754.h:34
int IntegerExponent() const
Definition: ieee754.h:63
static const uint64_t kSignificandMask
Definition: ieee754.h:86
static const int kExponentBias
Definition: ieee754.h:81
static const uint64_t kHiddenBit
Definition: ieee754.h:88
uint64_t ToBias() const
Definition: ieee754.h:66
int Exponent() const
Definition: ieee754.h:43


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46