@eosrio/node-abieos 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +4 -1
  2. package/dist/abieos.node +0 -0
  3. package/lib/abieos.d.ts +19 -0
  4. package/lib/abieos.d.ts.map +1 -0
  5. package/lib/abieos.js +100 -0
  6. package/lib/abieos.ts +107 -0
  7. package/package.json +13 -8
  8. package/.idea/modules.xml +0 -8
  9. package/.idea/node-abieos.iml +0 -12
  10. package/.idea/vcs.xml +0 -9
  11. package/.idea/workspace.xml +0 -66
  12. package/CMakeLists.txt +0 -35
  13. package/abieos.d.ts +0 -21
  14. package/abieos.js +0 -59
  15. package/eosio.json +0 -1596
  16. package/include/.clang-format +0 -76
  17. package/include/eosio/abi.hpp +0 -393
  18. package/include/eosio/asset.hpp +0 -458
  19. package/include/eosio/bytes.hpp +0 -27
  20. package/include/eosio/chain_conversions.hpp +0 -450
  21. package/include/eosio/chain_types.hpp +0 -14
  22. package/include/eosio/check.hpp +0 -178
  23. package/include/eosio/convert.hpp +0 -95
  24. package/include/eosio/crypto.hpp +0 -148
  25. package/include/eosio/eosio_outcome.hpp +0 -41
  26. package/include/eosio/fixed_bytes.hpp +0 -250
  27. package/include/eosio/float.hpp +0 -35
  28. package/include/eosio/for_each_field.hpp +0 -48
  29. package/include/eosio/fpconv.c +0 -336
  30. package/include/eosio/fpconv.h +0 -41
  31. package/include/eosio/fpconv.license +0 -23
  32. package/include/eosio/from_bin.hpp +0 -272
  33. package/include/eosio/from_json.hpp +0 -749
  34. package/include/eosio/from_string.hpp +0 -28
  35. package/include/eosio/map_macro.h +0 -64
  36. package/include/eosio/murmur.hpp +0 -55
  37. package/include/eosio/name.hpp +0 -178
  38. package/include/eosio/opaque.hpp +0 -184
  39. package/include/eosio/operators.hpp +0 -71
  40. package/include/eosio/powers.h +0 -76
  41. package/include/eosio/reflection.hpp +0 -61
  42. package/include/eosio/ship_protocol.hpp +0 -971
  43. package/include/eosio/stream.hpp +0 -235
  44. package/include/eosio/symbol.hpp +0 -300
  45. package/include/eosio/time.hpp +0 -264
  46. package/include/eosio/to_bin.hpp +0 -189
  47. package/include/eosio/to_json.hpp +0 -334
  48. package/include/eosio/to_key.hpp +0 -305
  49. package/include/eosio/types.hpp +0 -103
  50. package/include/eosio/varint.hpp +0 -452
  51. package/include/outcome-basic.hpp +0 -6836
  52. package/include/rapidjson/allocators.h +0 -284
  53. package/include/rapidjson/cursorstreamwrapper.h +0 -78
  54. package/include/rapidjson/document.h +0 -2646
  55. package/include/rapidjson/encodedstream.h +0 -299
  56. package/include/rapidjson/encodings.h +0 -716
  57. package/include/rapidjson/error/en.h +0 -74
  58. package/include/rapidjson/error/error.h +0 -161
  59. package/include/rapidjson/filereadstream.h +0 -99
  60. package/include/rapidjson/filewritestream.h +0 -104
  61. package/include/rapidjson/fwd.h +0 -151
  62. package/include/rapidjson/internal/biginteger.h +0 -290
  63. package/include/rapidjson/internal/diyfp.h +0 -271
  64. package/include/rapidjson/internal/dtoa.h +0 -245
  65. package/include/rapidjson/internal/ieee754.h +0 -78
  66. package/include/rapidjson/internal/itoa.h +0 -308
  67. package/include/rapidjson/internal/meta.h +0 -186
  68. package/include/rapidjson/internal/pow10.h +0 -55
  69. package/include/rapidjson/internal/regex.h +0 -732
  70. package/include/rapidjson/internal/stack.h +0 -231
  71. package/include/rapidjson/internal/strfunc.h +0 -69
  72. package/include/rapidjson/internal/strtod.h +0 -290
  73. package/include/rapidjson/internal/swap.h +0 -46
  74. package/include/rapidjson/istreamwrapper.h +0 -113
  75. package/include/rapidjson/memorybuffer.h +0 -70
  76. package/include/rapidjson/memorystream.h +0 -71
  77. package/include/rapidjson/msinttypes/inttypes.h +0 -316
  78. package/include/rapidjson/msinttypes/stdint.h +0 -300
  79. package/include/rapidjson/ostreamwrapper.h +0 -81
  80. package/include/rapidjson/pointer.h +0 -1357
  81. package/include/rapidjson/prettywriter.h +0 -277
  82. package/include/rapidjson/rapidjson.h +0 -654
  83. package/include/rapidjson/reader.h +0 -2230
  84. package/include/rapidjson/schema.h +0 -2494
  85. package/include/rapidjson/stream.h +0 -223
  86. package/include/rapidjson/stringbuffer.h +0 -121
  87. package/include/rapidjson/writer.h +0 -710
  88. package/src/abi.cpp +0 -274
  89. package/src/abieos.cpp +0 -334
  90. package/src/abieos.h +0 -91
  91. package/src/abieos.hpp +0 -1011
  92. package/src/abieos_exception.hpp +0 -89
  93. package/src/abieos_numeric.hpp +0 -94
  94. package/src/abieos_ripemd160.hpp +0 -417
  95. package/src/crypto.cpp +0 -215
  96. package/src/main.cpp +0 -242
  97. package/src/ship.abi.cpp +0 -695
  98. package/tools/CMakeLists.txt +0 -9
  99. package/tools/name.cpp +0 -86
@@ -1,231 +0,0 @@
1
- // Tencent is pleased to support the open source community by making RapidJSON available.
2
- //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
- //
5
- // Licensed under the MIT License (the "License"); you may not use this file except
6
- // in compliance with the License. You may obtain a copy of the License at
7
- //
8
- // http://opensource.org/licenses/MIT
9
- //
10
- // Unless required by applicable law or agreed to in writing, software distributed
11
- // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
- // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
- // specific language governing permissions and limitations under the License.
14
-
15
- #ifndef RAPIDJSON_INTERNAL_STACK_H_
16
- #define RAPIDJSON_INTERNAL_STACK_H_
17
-
18
- #include "../allocators.h"
19
- #include "swap.h"
20
-
21
- #if defined(__clang__)
22
- RAPIDJSON_DIAG_PUSH
23
- RAPIDJSON_DIAG_OFF(c++98-compat)
24
- #endif
25
-
26
- RAPIDJSON_NAMESPACE_BEGIN
27
- namespace internal {
28
-
29
- ///////////////////////////////////////////////////////////////////////////////
30
- // Stack
31
-
32
- //! A type-unsafe stack for storing different types of data.
33
- /*! \tparam Allocator Allocator for allocating stack memory.
34
- */
35
- template <typename Allocator>
36
- class Stack {
37
- public:
38
- // Optimization note: Do not allocate memory for stack_ in constructor.
39
- // Do it lazily when first Push() -> Expand() -> Resize().
40
- Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) {
41
- }
42
-
43
- #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
44
- Stack(Stack&& rhs)
45
- : allocator_(rhs.allocator_),
46
- ownAllocator_(rhs.ownAllocator_),
47
- stack_(rhs.stack_),
48
- stackTop_(rhs.stackTop_),
49
- stackEnd_(rhs.stackEnd_),
50
- initialCapacity_(rhs.initialCapacity_)
51
- {
52
- rhs.allocator_ = 0;
53
- rhs.ownAllocator_ = 0;
54
- rhs.stack_ = 0;
55
- rhs.stackTop_ = 0;
56
- rhs.stackEnd_ = 0;
57
- rhs.initialCapacity_ = 0;
58
- }
59
- #endif
60
-
61
- ~Stack() {
62
- Destroy();
63
- }
64
-
65
- #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
66
- Stack& operator=(Stack&& rhs) {
67
- if (&rhs != this)
68
- {
69
- Destroy();
70
-
71
- allocator_ = rhs.allocator_;
72
- ownAllocator_ = rhs.ownAllocator_;
73
- stack_ = rhs.stack_;
74
- stackTop_ = rhs.stackTop_;
75
- stackEnd_ = rhs.stackEnd_;
76
- initialCapacity_ = rhs.initialCapacity_;
77
-
78
- rhs.allocator_ = 0;
79
- rhs.ownAllocator_ = 0;
80
- rhs.stack_ = 0;
81
- rhs.stackTop_ = 0;
82
- rhs.stackEnd_ = 0;
83
- rhs.initialCapacity_ = 0;
84
- }
85
- return *this;
86
- }
87
- #endif
88
-
89
- void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT {
90
- internal::Swap(allocator_, rhs.allocator_);
91
- internal::Swap(ownAllocator_, rhs.ownAllocator_);
92
- internal::Swap(stack_, rhs.stack_);
93
- internal::Swap(stackTop_, rhs.stackTop_);
94
- internal::Swap(stackEnd_, rhs.stackEnd_);
95
- internal::Swap(initialCapacity_, rhs.initialCapacity_);
96
- }
97
-
98
- void Clear() { stackTop_ = stack_; }
99
-
100
- void ShrinkToFit() {
101
- if (Empty()) {
102
- // If the stack is empty, completely deallocate the memory.
103
- Allocator::Free(stack_); // NOLINT (+clang-analyzer-unix.Malloc)
104
- stack_ = 0;
105
- stackTop_ = 0;
106
- stackEnd_ = 0;
107
- }
108
- else
109
- Resize(GetSize());
110
- }
111
-
112
- // Optimization note: try to minimize the size of this function for force inline.
113
- // Expansion is run very infrequently, so it is moved to another (probably non-inline) function.
114
- template<typename T>
115
- RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) {
116
- // Expand the stack if needed
117
- if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_))
118
- Expand<T>(count);
119
- }
120
-
121
- template<typename T>
122
- RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) {
123
- Reserve<T>(count);
124
- return PushUnsafe<T>(count);
125
- }
126
-
127
- template<typename T>
128
- RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) {
129
- RAPIDJSON_ASSERT(stackTop_);
130
- RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_);
131
- T* ret = reinterpret_cast<T*>(stackTop_);
132
- stackTop_ += sizeof(T) * count;
133
- return ret;
134
- }
135
-
136
- template<typename T>
137
- T* Pop(size_t count) {
138
- RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T));
139
- stackTop_ -= count * sizeof(T);
140
- return reinterpret_cast<T*>(stackTop_);
141
- }
142
-
143
- template<typename T>
144
- T* Top() {
145
- RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
146
- return reinterpret_cast<T*>(stackTop_ - sizeof(T));
147
- }
148
-
149
- template<typename T>
150
- const T* Top() const {
151
- RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
152
- return reinterpret_cast<T*>(stackTop_ - sizeof(T));
153
- }
154
-
155
- template<typename T>
156
- T* End() { return reinterpret_cast<T*>(stackTop_); }
157
-
158
- template<typename T>
159
- const T* End() const { return reinterpret_cast<T*>(stackTop_); }
160
-
161
- template<typename T>
162
- T* Bottom() { return reinterpret_cast<T*>(stack_); }
163
-
164
- template<typename T>
165
- const T* Bottom() const { return reinterpret_cast<T*>(stack_); }
166
-
167
- bool HasAllocator() const {
168
- return allocator_ != 0;
169
- }
170
-
171
- Allocator& GetAllocator() {
172
- RAPIDJSON_ASSERT(allocator_);
173
- return *allocator_;
174
- }
175
-
176
- bool Empty() const { return stackTop_ == stack_; }
177
- size_t GetSize() const { return static_cast<size_t>(stackTop_ - stack_); }
178
- size_t GetCapacity() const { return static_cast<size_t>(stackEnd_ - stack_); }
179
-
180
- private:
181
- template<typename T>
182
- void Expand(size_t count) {
183
- // Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity.
184
- size_t newCapacity;
185
- if (stack_ == 0) {
186
- if (!allocator_)
187
- ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
188
- newCapacity = initialCapacity_;
189
- } else {
190
- newCapacity = GetCapacity();
191
- newCapacity += (newCapacity + 1) / 2;
192
- }
193
- size_t newSize = GetSize() + sizeof(T) * count;
194
- if (newCapacity < newSize)
195
- newCapacity = newSize;
196
-
197
- Resize(newCapacity);
198
- }
199
-
200
- void Resize(size_t newCapacity) {
201
- const size_t size = GetSize(); // Backup the current size
202
- stack_ = static_cast<char*>(allocator_->Realloc(stack_, GetCapacity(), newCapacity));
203
- stackTop_ = stack_ + size;
204
- stackEnd_ = stack_ + newCapacity;
205
- }
206
-
207
- void Destroy() {
208
- Allocator::Free(stack_);
209
- RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack
210
- }
211
-
212
- // Prohibit copy constructor & assignment operator.
213
- Stack(const Stack&);
214
- Stack& operator=(const Stack&);
215
-
216
- Allocator* allocator_;
217
- Allocator* ownAllocator_;
218
- char *stack_;
219
- char *stackTop_;
220
- char *stackEnd_;
221
- size_t initialCapacity_;
222
- };
223
-
224
- } // namespace internal
225
- RAPIDJSON_NAMESPACE_END
226
-
227
- #if defined(__clang__)
228
- RAPIDJSON_DIAG_POP
229
- #endif
230
-
231
- #endif // RAPIDJSON_STACK_H_
@@ -1,69 +0,0 @@
1
- // Tencent is pleased to support the open source community by making RapidJSON available.
2
- //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
- //
5
- // Licensed under the MIT License (the "License"); you may not use this file except
6
- // in compliance with the License. You may obtain a copy of the License at
7
- //
8
- // http://opensource.org/licenses/MIT
9
- //
10
- // Unless required by applicable law or agreed to in writing, software distributed
11
- // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
- // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
- // specific language governing permissions and limitations under the License.
14
-
15
- #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_
16
- #define RAPIDJSON_INTERNAL_STRFUNC_H_
17
-
18
- #include "../stream.h"
19
- #include <cwchar>
20
-
21
- RAPIDJSON_NAMESPACE_BEGIN
22
- namespace internal {
23
-
24
- //! Custom strlen() which works on different character types.
25
- /*! \tparam Ch Character type (e.g. char, wchar_t, short)
26
- \param s Null-terminated input string.
27
- \return Number of characters in the string.
28
- \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints.
29
- */
30
- template <typename Ch>
31
- inline SizeType StrLen(const Ch* s) {
32
- RAPIDJSON_ASSERT(s != 0);
33
- const Ch* p = s;
34
- while (*p) ++p;
35
- return SizeType(p - s);
36
- }
37
-
38
- template <>
39
- inline SizeType StrLen(const char* s) {
40
- return SizeType(std::strlen(s));
41
- }
42
-
43
- template <>
44
- inline SizeType StrLen(const wchar_t* s) {
45
- return SizeType(std::wcslen(s));
46
- }
47
-
48
- //! Returns number of code points in a encoded string.
49
- template<typename Encoding>
50
- bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {
51
- RAPIDJSON_ASSERT(s != 0);
52
- RAPIDJSON_ASSERT(outCount != 0);
53
- GenericStringStream<Encoding> is(s);
54
- const typename Encoding::Ch* end = s + length;
55
- SizeType count = 0;
56
- while (is.src_ < end) {
57
- unsigned codepoint;
58
- if (!Encoding::Decode(is, &codepoint))
59
- return false;
60
- count++;
61
- }
62
- *outCount = count;
63
- return true;
64
- }
65
-
66
- } // namespace internal
67
- RAPIDJSON_NAMESPACE_END
68
-
69
- #endif // RAPIDJSON_INTERNAL_STRFUNC_H_
@@ -1,290 +0,0 @@
1
- // Tencent is pleased to support the open source community by making RapidJSON available.
2
- //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
- //
5
- // Licensed under the MIT License (the "License"); you may not use this file except
6
- // in compliance with the License. You may obtain a copy of the License at
7
- //
8
- // http://opensource.org/licenses/MIT
9
- //
10
- // Unless required by applicable law or agreed to in writing, software distributed
11
- // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
- // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
- // specific language governing permissions and limitations under the License.
14
-
15
- #ifndef RAPIDJSON_STRTOD_
16
- #define RAPIDJSON_STRTOD_
17
-
18
- #include "ieee754.h"
19
- #include "biginteger.h"
20
- #include "diyfp.h"
21
- #include "pow10.h"
22
- #include <climits>
23
- #include <limits>
24
-
25
- RAPIDJSON_NAMESPACE_BEGIN
26
- namespace internal {
27
-
28
- inline double FastPath(double significand, int exp) {
29
- if (exp < -308)
30
- return 0.0;
31
- else if (exp >= 0)
32
- return significand * internal::Pow10(exp);
33
- else
34
- return significand / internal::Pow10(-exp);
35
- }
36
-
37
- inline double StrtodNormalPrecision(double d, int p) {
38
- if (p < -308) {
39
- // Prevent expSum < -308, making Pow10(p) = 0
40
- d = FastPath(d, -308);
41
- d = FastPath(d, p + 308);
42
- }
43
- else
44
- d = FastPath(d, p);
45
- return d;
46
- }
47
-
48
- template <typename T>
49
- inline T Min3(T a, T b, T c) {
50
- T m = a;
51
- if (m > b) m = b;
52
- if (m > c) m = c;
53
- return m;
54
- }
55
-
56
- inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) {
57
- const Double db(b);
58
- const uint64_t bInt = db.IntegerSignificand();
59
- const int bExp = db.IntegerExponent();
60
- const int hExp = bExp - 1;
61
-
62
- int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0;
63
-
64
- // Adjust for decimal exponent
65
- if (dExp >= 0) {
66
- dS_Exp2 += dExp;
67
- dS_Exp5 += dExp;
68
- }
69
- else {
70
- bS_Exp2 -= dExp;
71
- bS_Exp5 -= dExp;
72
- hS_Exp2 -= dExp;
73
- hS_Exp5 -= dExp;
74
- }
75
-
76
- // Adjust for binary exponent
77
- if (bExp >= 0)
78
- bS_Exp2 += bExp;
79
- else {
80
- dS_Exp2 -= bExp;
81
- hS_Exp2 -= bExp;
82
- }
83
-
84
- // Adjust for half ulp exponent
85
- if (hExp >= 0)
86
- hS_Exp2 += hExp;
87
- else {
88
- dS_Exp2 -= hExp;
89
- bS_Exp2 -= hExp;
90
- }
91
-
92
- // Remove common power of two factor from all three scaled values
93
- int common_Exp2 = Min3(dS_Exp2, bS_Exp2, hS_Exp2);
94
- dS_Exp2 -= common_Exp2;
95
- bS_Exp2 -= common_Exp2;
96
- hS_Exp2 -= common_Exp2;
97
-
98
- BigInteger dS = d;
99
- dS.MultiplyPow5(static_cast<unsigned>(dS_Exp5)) <<= static_cast<unsigned>(dS_Exp2);
100
-
101
- BigInteger bS(bInt);
102
- bS.MultiplyPow5(static_cast<unsigned>(bS_Exp5)) <<= static_cast<unsigned>(bS_Exp2);
103
-
104
- BigInteger hS(1);
105
- hS.MultiplyPow5(static_cast<unsigned>(hS_Exp5)) <<= static_cast<unsigned>(hS_Exp2);
106
-
107
- BigInteger delta(0);
108
- dS.Difference(bS, &delta);
109
-
110
- return delta.Compare(hS);
111
- }
112
-
113
- inline bool StrtodFast(double d, int p, double* result) {
114
- // Use fast path for string-to-double conversion if possible
115
- // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/
116
- if (p > 22 && p < 22 + 16) {
117
- // Fast Path Cases In Disguise
118
- d *= internal::Pow10(p - 22);
119
- p = 22;
120
- }
121
-
122
- if (p >= -22 && p <= 22 && d <= 9007199254740991.0) { // 2^53 - 1
123
- *result = FastPath(d, p);
124
- return true;
125
- }
126
- else
127
- return false;
128
- }
129
-
130
- // Compute an approximation and see if it is within 1/2 ULP
131
- inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result) {
132
- uint64_t significand = 0;
133
- int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999
134
- for (; i < dLen; i++) {
135
- if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) ||
136
- (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > '5'))
137
- break;
138
- significand = significand * 10u + static_cast<unsigned>(decimals[i] - '0');
139
- }
140
-
141
- if (i < dLen && decimals[i] >= '5') // Rounding
142
- significand++;
143
-
144
- int remaining = dLen - i;
145
- const int kUlpShift = 3;
146
- const int kUlp = 1 << kUlpShift;
147
- int64_t error = (remaining == 0) ? 0 : kUlp / 2;
148
-
149
- DiyFp v(significand, 0);
150
- v = v.Normalize();
151
- error <<= -v.e;
152
-
153
- dExp += remaining;
154
-
155
- int actualExp;
156
- DiyFp cachedPower = GetCachedPower10(dExp, &actualExp);
157
- if (actualExp != dExp) {
158
- static const DiyFp kPow10[] = {
159
- DiyFp(RAPIDJSON_UINT64_C2(0xa0000000, 0x00000000), -60), // 10^1
160
- DiyFp(RAPIDJSON_UINT64_C2(0xc8000000, 0x00000000), -57), // 10^2
161
- DiyFp(RAPIDJSON_UINT64_C2(0xfa000000, 0x00000000), -54), // 10^3
162
- DiyFp(RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), -50), // 10^4
163
- DiyFp(RAPIDJSON_UINT64_C2(0xc3500000, 0x00000000), -47), // 10^5
164
- DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 0x00000000), -44), // 10^6
165
- DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 0x00000000), -40) // 10^7
166
- };
167
- int adjustment = dExp - actualExp;
168
- RAPIDJSON_ASSERT(adjustment >= 1 && adjustment < 8);
169
- v = v * kPow10[adjustment - 1];
170
- if (dLen + adjustment > 19) // has more digits than decimal digits in 64-bit
171
- error += kUlp / 2;
172
- }
173
-
174
- v = v * cachedPower;
175
-
176
- error += kUlp + (error == 0 ? 0 : 1);
177
-
178
- const int oldExp = v.e;
179
- v = v.Normalize();
180
- error <<= oldExp - v.e;
181
-
182
- const int effectiveSignificandSize = Double::EffectiveSignificandSize(64 + v.e);
183
- int precisionSize = 64 - effectiveSignificandSize;
184
- if (precisionSize + kUlpShift >= 64) {
185
- int scaleExp = (precisionSize + kUlpShift) - 63;
186
- v.f >>= scaleExp;
187
- v.e += scaleExp;
188
- error = (error >> scaleExp) + 1 + kUlp;
189
- precisionSize -= scaleExp;
190
- }
191
-
192
- DiyFp rounded(v.f >> precisionSize, v.e + precisionSize);
193
- const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp;
194
- const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp;
195
- if (precisionBits >= halfWay + static_cast<unsigned>(error)) {
196
- rounded.f++;
197
- if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340)
198
- rounded.f >>= 1;
199
- rounded.e++;
200
- }
201
- }
202
-
203
- *result = rounded.ToDouble();
204
-
205
- return halfWay - static_cast<unsigned>(error) >= precisionBits || precisionBits >= halfWay + static_cast<unsigned>(error);
206
- }
207
-
208
- inline double StrtodBigInteger(double approx, const char* decimals, int dLen, int dExp) {
209
- RAPIDJSON_ASSERT(dLen >= 0);
210
- const BigInteger dInt(decimals, static_cast<unsigned>(dLen));
211
- Double a(approx);
212
- int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp);
213
- if (cmp < 0)
214
- return a.Value(); // within half ULP
215
- else if (cmp == 0) {
216
- // Round towards even
217
- if (a.Significand() & 1)
218
- return a.NextPositiveDouble();
219
- else
220
- return a.Value();
221
- }
222
- else // adjustment
223
- return a.NextPositiveDouble();
224
- }
225
-
226
- inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) {
227
- RAPIDJSON_ASSERT(d >= 0.0);
228
- RAPIDJSON_ASSERT(length >= 1);
229
-
230
- double result = 0.0;
231
- if (StrtodFast(d, p, &result))
232
- return result;
233
-
234
- RAPIDJSON_ASSERT(length <= INT_MAX);
235
- int dLen = static_cast<int>(length);
236
-
237
- RAPIDJSON_ASSERT(length >= decimalPosition);
238
- RAPIDJSON_ASSERT(length - decimalPosition <= INT_MAX);
239
- int dExpAdjust = static_cast<int>(length - decimalPosition);
240
-
241
- RAPIDJSON_ASSERT(exp >= INT_MIN + dExpAdjust);
242
- int dExp = exp - dExpAdjust;
243
-
244
- // Make sure length+dExp does not overflow
245
- RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen);
246
-
247
- // Trim leading zeros
248
- while (dLen > 0 && *decimals == '0') {
249
- dLen--;
250
- decimals++;
251
- }
252
-
253
- // Trim trailing zeros
254
- while (dLen > 0 && decimals[dLen - 1] == '0') {
255
- dLen--;
256
- dExp++;
257
- }
258
-
259
- if (dLen == 0) { // Buffer only contains zeros.
260
- return 0.0;
261
- }
262
-
263
- // Trim right-most digits
264
- const int kMaxDecimalDigit = 767 + 1;
265
- if (dLen > kMaxDecimalDigit) {
266
- dExp += dLen - kMaxDecimalDigit;
267
- dLen = kMaxDecimalDigit;
268
- }
269
-
270
- // If too small, underflow to zero.
271
- // Any x <= 10^-324 is interpreted as zero.
272
- if (dLen + dExp <= -324)
273
- return 0.0;
274
-
275
- // If too large, overflow to infinity.
276
- // Any x >= 10^309 is interpreted as +infinity.
277
- if (dLen + dExp > 309)
278
- return std::numeric_limits<double>::infinity();
279
-
280
- if (StrtodDiyFp(decimals, dLen, dExp, &result))
281
- return result;
282
-
283
- // Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison
284
- return StrtodBigInteger(result, decimals, dLen, dExp);
285
- }
286
-
287
- } // namespace internal
288
- RAPIDJSON_NAMESPACE_END
289
-
290
- #endif // RAPIDJSON_STRTOD_
@@ -1,46 +0,0 @@
1
- // Tencent is pleased to support the open source community by making RapidJSON available.
2
- //
3
- // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved.
4
- //
5
- // Licensed under the MIT License (the "License"); you may not use this file except
6
- // in compliance with the License. You may obtain a copy of the License at
7
- //
8
- // http://opensource.org/licenses/MIT
9
- //
10
- // Unless required by applicable law or agreed to in writing, software distributed
11
- // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
- // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
- // specific language governing permissions and limitations under the License.
14
-
15
- #ifndef RAPIDJSON_INTERNAL_SWAP_H_
16
- #define RAPIDJSON_INTERNAL_SWAP_H_
17
-
18
- #include "../rapidjson.h"
19
-
20
- #if defined(__clang__)
21
- RAPIDJSON_DIAG_PUSH
22
- RAPIDJSON_DIAG_OFF(c++98-compat)
23
- #endif
24
-
25
- RAPIDJSON_NAMESPACE_BEGIN
26
- namespace internal {
27
-
28
- //! Custom swap() to avoid dependency on C++ <algorithm> header
29
- /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only.
30
- \note This has the same semantics as std::swap().
31
- */
32
- template <typename T>
33
- inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT {
34
- T tmp = a;
35
- a = b;
36
- b = tmp;
37
- }
38
-
39
- } // namespace internal
40
- RAPIDJSON_NAMESPACE_END
41
-
42
- #if defined(__clang__)
43
- RAPIDJSON_DIAG_POP
44
- #endif
45
-
46
- #endif // RAPIDJSON_INTERNAL_SWAP_H_