Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ieee754.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2// Tencent is pleased to support the open source community by making RapidJSON available.
3//
4// Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
5//
6// Licensed under the MIT License (the "License"); you may not use this file except
7// in compliance with the License. You may obtain a copy of the License at
8//
9// http://opensource.org/licenses/MIT
10//
11// Unless required by applicable law or agreed to in writing, software distributed
12// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14// specific language governing permissions and limitations under the License.
15
16#ifndef RAPIDJSON_IEEE754_
17#define RAPIDJSON_IEEE754_
18
19#include "../rapidjson.h"
20
22namespace internal {
23
24class Double {
25public:
26 Double() {}
27 Double(double d) : d_(d) {}
28 Double(uint64_t u) : u_(u) {}
29
30 double Value() const { return d_; }
31 uint64_t Uint64Value() const { return u_; }
32
33 double NextPositiveDouble() const {
34 RAPIDJSON_ASSERT(!Sign());
35 return Double(u_ + 1).Value();
36 }
37
38 bool Sign() const { return (u_ & kSignMask) != 0; }
39 uint64_t Significand() const { return u_ & kSignificandMask; }
40 int Exponent() const { return static_cast<int>(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); }
41
42 bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; }
43 bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; }
44 bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; }
45 bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; }
46 bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; }
47
48 uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); }
49 int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; }
50 uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; }
51
52 static int EffectiveSignificandSize(int order) {
53 if (order >= -1021)
54 return 53;
55 else if (order <= -1074)
56 return 0;
57 else
58 return order + 1074;
59 }
60
61private:
62 static const int kSignificandSize = 52;
63 static const int kExponentBias = 0x3FF;
64 static const int kDenormalExponent = 1 - kExponentBias;
65 static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000);
66 static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000);
67 static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF);
68 static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000);
69
70 union {
71 double d_;
72 uint64_t u_;
73 };
74};
75
76} // namespace internal
78
79#endif // RAPIDJSON_IEEE754_
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Represents a JSON value. Use Value for UTF8 encoding and default allocator.
Definition document.h:609
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition rapidjson.h:407
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition rapidjson.h:122
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition rapidjson.h:125
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition rapidjson.h:290