quickfix_ruby_ud 2.0.7-aarch64-linux

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 (205) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +257 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +137 -0
  6. data/ext/quickfix/DOMDocument.h +70 -0
  7. data/ext/quickfix/DataDictionary.cpp +679 -0
  8. data/ext/quickfix/DataDictionary.h +607 -0
  9. data/ext/quickfix/DataDictionaryProvider.cpp +66 -0
  10. data/ext/quickfix/DataDictionaryProvider.h +67 -0
  11. data/ext/quickfix/DatabaseConnectionID.h +98 -0
  12. data/ext/quickfix/DatabaseConnectionPool.h +84 -0
  13. data/ext/quickfix/Dictionary.cpp +157 -0
  14. data/ext/quickfix/Dictionary.h +89 -0
  15. data/ext/quickfix/Event.h +89 -0
  16. data/ext/quickfix/Except.h +39 -0
  17. data/ext/quickfix/Exceptions.h +257 -0
  18. data/ext/quickfix/Field.h +654 -0
  19. data/ext/quickfix/FieldConvertors.cpp +86 -0
  20. data/ext/quickfix/FieldConvertors.h +800 -0
  21. data/ext/quickfix/FieldMap.cpp +254 -0
  22. data/ext/quickfix/FieldMap.h +327 -0
  23. data/ext/quickfix/FieldNumbers.h +44 -0
  24. data/ext/quickfix/FieldTypes.cpp +62 -0
  25. data/ext/quickfix/FieldTypes.h +817 -0
  26. data/ext/quickfix/Fields.h +30 -0
  27. data/ext/quickfix/FileLog.cpp +176 -0
  28. data/ext/quickfix/FileLog.h +110 -0
  29. data/ext/quickfix/FileStore.cpp +369 -0
  30. data/ext/quickfix/FileStore.h +131 -0
  31. data/ext/quickfix/FixCommonFields.h +13 -0
  32. data/ext/quickfix/FixFieldNumbers.h +6132 -0
  33. data/ext/quickfix/FixFields.h +6133 -0
  34. data/ext/quickfix/FixValues.h +5790 -0
  35. data/ext/quickfix/Group.cpp +44 -0
  36. data/ext/quickfix/Group.h +78 -0
  37. data/ext/quickfix/HostDetailsProvider.cpp +79 -0
  38. data/ext/quickfix/HostDetailsProvider.h +44 -0
  39. data/ext/quickfix/HtmlBuilder.h +178 -0
  40. data/ext/quickfix/HttpConnection.cpp +914 -0
  41. data/ext/quickfix/HttpConnection.h +74 -0
  42. data/ext/quickfix/HttpMessage.cpp +229 -0
  43. data/ext/quickfix/HttpMessage.h +112 -0
  44. data/ext/quickfix/HttpParser.cpp +49 -0
  45. data/ext/quickfix/HttpParser.h +49 -0
  46. data/ext/quickfix/HttpServer.cpp +152 -0
  47. data/ext/quickfix/HttpServer.h +76 -0
  48. data/ext/quickfix/Initiator.cpp +310 -0
  49. data/ext/quickfix/Initiator.h +151 -0
  50. data/ext/quickfix/Log.cpp +71 -0
  51. data/ext/quickfix/Log.h +254 -0
  52. data/ext/quickfix/Message.cpp +617 -0
  53. data/ext/quickfix/Message.h +419 -0
  54. data/ext/quickfix/MessageCracker.h +171 -0
  55. data/ext/quickfix/MessageSorters.cpp +101 -0
  56. data/ext/quickfix/MessageSorters.h +185 -0
  57. data/ext/quickfix/MessageStore.cpp +182 -0
  58. data/ext/quickfix/MessageStore.h +164 -0
  59. data/ext/quickfix/Mutex.h +120 -0
  60. data/ext/quickfix/MySQLConnection.h +187 -0
  61. data/ext/quickfix/MySQLLog.cpp +262 -0
  62. data/ext/quickfix/MySQLLog.h +158 -0
  63. data/ext/quickfix/MySQLStore.cpp +323 -0
  64. data/ext/quickfix/MySQLStore.h +161 -0
  65. data/ext/quickfix/MySQLStubs.h +203 -0
  66. data/ext/quickfix/NullStore.cpp +40 -0
  67. data/ext/quickfix/NullStore.h +89 -0
  68. data/ext/quickfix/OdbcConnection.h +241 -0
  69. data/ext/quickfix/OdbcLog.cpp +230 -0
  70. data/ext/quickfix/OdbcLog.h +109 -0
  71. data/ext/quickfix/OdbcStore.cpp +313 -0
  72. data/ext/quickfix/OdbcStore.h +124 -0
  73. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  74. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  75. data/ext/quickfix/Parser.cpp +111 -0
  76. data/ext/quickfix/Parser.h +50 -0
  77. data/ext/quickfix/PostgreSQLConnection.h +163 -0
  78. data/ext/quickfix/PostgreSQLLog.cpp +263 -0
  79. data/ext/quickfix/PostgreSQLLog.h +157 -0
  80. data/ext/quickfix/PostgreSQLStore.cpp +327 -0
  81. data/ext/quickfix/PostgreSQLStore.h +160 -0
  82. data/ext/quickfix/PostgreSQLStubs.h +203 -0
  83. data/ext/quickfix/Queue.h +66 -0
  84. data/ext/quickfix/QuickfixRuby.cpp +131900 -0
  85. data/ext/quickfix/QuickfixRuby.h +56 -0
  86. data/ext/quickfix/Responder.h +41 -0
  87. data/ext/quickfix/SSLSocketAcceptor.cpp +409 -0
  88. data/ext/quickfix/SSLSocketAcceptor.h +186 -0
  89. data/ext/quickfix/SSLSocketConnection.cpp +434 -0
  90. data/ext/quickfix/SSLSocketConnection.h +221 -0
  91. data/ext/quickfix/SSLSocketInitiator.cpp +558 -0
  92. data/ext/quickfix/SSLSocketInitiator.h +203 -0
  93. data/ext/quickfix/SSLStubs.h +129 -0
  94. data/ext/quickfix/Session.cpp +1437 -0
  95. data/ext/quickfix/Session.h +343 -0
  96. data/ext/quickfix/SessionFactory.cpp +314 -0
  97. data/ext/quickfix/SessionFactory.h +84 -0
  98. data/ext/quickfix/SessionID.h +136 -0
  99. data/ext/quickfix/SessionSettings.cpp +165 -0
  100. data/ext/quickfix/SessionSettings.h +283 -0
  101. data/ext/quickfix/SessionState.h +260 -0
  102. data/ext/quickfix/Settings.cpp +160 -0
  103. data/ext/quickfix/Settings.h +56 -0
  104. data/ext/quickfix/SharedArray.h +274 -0
  105. data/ext/quickfix/SocketAcceptor.cpp +216 -0
  106. data/ext/quickfix/SocketAcceptor.h +77 -0
  107. data/ext/quickfix/SocketConnection.cpp +256 -0
  108. data/ext/quickfix/SocketConnection.h +102 -0
  109. data/ext/quickfix/SocketConnector.cpp +112 -0
  110. data/ext/quickfix/SocketConnector.h +76 -0
  111. data/ext/quickfix/SocketInitiator.cpp +241 -0
  112. data/ext/quickfix/SocketInitiator.h +76 -0
  113. data/ext/quickfix/SocketMonitor.h +26 -0
  114. data/ext/quickfix/SocketMonitor_UNIX.cpp +238 -0
  115. data/ext/quickfix/SocketMonitor_UNIX.h +101 -0
  116. data/ext/quickfix/SocketMonitor_WIN32.cpp +248 -0
  117. data/ext/quickfix/SocketMonitor_WIN32.h +99 -0
  118. data/ext/quickfix/SocketServer.cpp +163 -0
  119. data/ext/quickfix/SocketServer.h +100 -0
  120. data/ext/quickfix/ThreadedSSLSocketAcceptor.cpp +436 -0
  121. data/ext/quickfix/ThreadedSSLSocketAcceptor.h +209 -0
  122. data/ext/quickfix/ThreadedSSLSocketConnection.cpp +364 -0
  123. data/ext/quickfix/ThreadedSSLSocketConnection.h +191 -0
  124. data/ext/quickfix/ThreadedSSLSocketInitiator.cpp +434 -0
  125. data/ext/quickfix/ThreadedSSLSocketInitiator.h +193 -0
  126. data/ext/quickfix/ThreadedSocketAcceptor.cpp +242 -0
  127. data/ext/quickfix/ThreadedSocketAcceptor.h +95 -0
  128. data/ext/quickfix/ThreadedSocketConnection.cpp +227 -0
  129. data/ext/quickfix/ThreadedSocketConnection.h +89 -0
  130. data/ext/quickfix/ThreadedSocketInitiator.cpp +238 -0
  131. data/ext/quickfix/ThreadedSocketInitiator.h +78 -0
  132. data/ext/quickfix/TimeRange.cpp +227 -0
  133. data/ext/quickfix/TimeRange.h +215 -0
  134. data/ext/quickfix/Utility.cpp +639 -0
  135. data/ext/quickfix/Utility.h +255 -0
  136. data/ext/quickfix/UtilitySSL.cpp +1612 -0
  137. data/ext/quickfix/UtilitySSL.h +274 -0
  138. data/ext/quickfix/Values.h +63 -0
  139. data/ext/quickfix/config-all.h +10 -0
  140. data/ext/quickfix/config.h +10 -0
  141. data/ext/quickfix/config_unix.h +178 -0
  142. data/ext/quickfix/config_windows.h +0 -0
  143. data/ext/quickfix/dirent_windows.h +838 -0
  144. data/ext/quickfix/double-conversion/bignum-dtoa.cc +641 -0
  145. data/ext/quickfix/double-conversion/bignum-dtoa.h +84 -0
  146. data/ext/quickfix/double-conversion/bignum.cc +766 -0
  147. data/ext/quickfix/double-conversion/bignum.h +144 -0
  148. data/ext/quickfix/double-conversion/cached-powers.cc +176 -0
  149. data/ext/quickfix/double-conversion/cached-powers.h +64 -0
  150. data/ext/quickfix/double-conversion/diy-fp.cc +57 -0
  151. data/ext/quickfix/double-conversion/diy-fp.h +118 -0
  152. data/ext/quickfix/double-conversion/double-conversion.cc +994 -0
  153. data/ext/quickfix/double-conversion/double-conversion.h +543 -0
  154. data/ext/quickfix/double-conversion/fast-dtoa.cc +665 -0
  155. data/ext/quickfix/double-conversion/fast-dtoa.h +88 -0
  156. data/ext/quickfix/double-conversion/fixed-dtoa.cc +404 -0
  157. data/ext/quickfix/double-conversion/fixed-dtoa.h +56 -0
  158. data/ext/quickfix/double-conversion/ieee.h +402 -0
  159. data/ext/quickfix/double-conversion/strtod.cc +557 -0
  160. data/ext/quickfix/double-conversion/strtod.h +45 -0
  161. data/ext/quickfix/double-conversion/utils.h +374 -0
  162. data/ext/quickfix/extconf.rb +76 -0
  163. data/ext/quickfix/index.h +37 -0
  164. data/ext/quickfix/pugiconfig.hpp +77 -0
  165. data/ext/quickfix/pugixml.cpp +13237 -0
  166. data/ext/quickfix/pugixml.hpp +1516 -0
  167. data/ext/quickfix/scope_guard.hpp +215 -0
  168. data/ext/quickfix/stdint_msvc.h +254 -0
  169. data/ext/quickfix/strptime.h +7 -0
  170. data/lib/2.4/quickfix.so +0 -0
  171. data/lib/2.5/quickfix.so +0 -0
  172. data/lib/2.6/quickfix.so +0 -0
  173. data/lib/2.7/quickfix.so +0 -0
  174. data/lib/3.0/quickfix.so +0 -0
  175. data/lib/3.1/quickfix.so +0 -0
  176. data/lib/3.2/quickfix.so +0 -0
  177. data/lib/3.3/quickfix.so +0 -0
  178. data/lib/3.4/quickfix.so +0 -0
  179. data/lib/quickfix40.rb +274 -0
  180. data/lib/quickfix41.rb +351 -0
  181. data/lib/quickfix42.rb +1184 -0
  182. data/lib/quickfix43.rb +3504 -0
  183. data/lib/quickfix44.rb +14040 -0
  184. data/lib/quickfix50.rb +20051 -0
  185. data/lib/quickfix50sp1.rb +23596 -0
  186. data/lib/quickfix50sp2.rb +412444 -0
  187. data/lib/quickfix_fields.rb +79393 -0
  188. data/lib/quickfix_ruby.rb +82 -0
  189. data/lib/quickfixt11.rb +65 -0
  190. data/spec/FIX40.xml +862 -0
  191. data/spec/FIX41.xml +1282 -0
  192. data/spec/FIX42.xml +2743 -0
  193. data/spec/FIX43.xml +4230 -0
  194. data/spec/FIX44.xml +6600 -0
  195. data/spec/FIX50.xml +8142 -0
  196. data/spec/FIX50SP1.xml +9506 -0
  197. data/spec/FIX50SP2.xml +26069 -0
  198. data/spec/FIXT11.xml +252 -0
  199. data/test/DataDictionaryTestCase.rb +268 -0
  200. data/test/DictionaryTestCase.rb +112 -0
  201. data/test/FieldBaseTestCase.rb +24 -0
  202. data/test/MessageStoreTestCase.rb +19 -0
  203. data/test/MessageTestCase.rb +368 -0
  204. data/test/SessionSettingsTestCase.rb +41 -0
  205. metadata +247 -0
@@ -0,0 +1,402 @@
1
+ // Copyright 2012 the V8 project authors. All rights reserved.
2
+ // Redistribution and use in source and binary forms, with or without
3
+ // modification, are permitted provided that the following conditions are
4
+ // met:
5
+ //
6
+ // * Redistributions of source code must retain the above copyright
7
+ // notice, this list of conditions and the following disclaimer.
8
+ // * Redistributions in binary form must reproduce the above
9
+ // copyright notice, this list of conditions and the following
10
+ // disclaimer in the documentation and/or other materials provided
11
+ // with the distribution.
12
+ // * Neither the name of Google Inc. nor the names of its
13
+ // contributors may be used to endorse or promote products derived
14
+ // from this software without specific prior written permission.
15
+ //
16
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
+
28
+ #ifndef DOUBLE_CONVERSION_DOUBLE_H_
29
+ #define DOUBLE_CONVERSION_DOUBLE_H_
30
+
31
+ #include "diy-fp.h"
32
+
33
+ namespace double_conversion {
34
+
35
+ // We assume that doubles and uint64_t have the same endianness.
36
+ static uint64_t double_to_uint64(double d) { return BitCast<uint64_t>(d); }
37
+ static double uint64_to_double(uint64_t d64) { return BitCast<double>(d64); }
38
+ static uint32_t float_to_uint32(float f) { return BitCast<uint32_t>(f); }
39
+ static float uint32_to_float(uint32_t d32) { return BitCast<float>(d32); }
40
+
41
+ // Helper functions for doubles.
42
+ class Double {
43
+ public:
44
+ static const uint64_t kSignMask = UINT64_2PART_C(0x80000000, 00000000);
45
+ static const uint64_t kExponentMask = UINT64_2PART_C(0x7FF00000, 00000000);
46
+ static const uint64_t kSignificandMask = UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
47
+ static const uint64_t kHiddenBit = UINT64_2PART_C(0x00100000, 00000000);
48
+ static const int kPhysicalSignificandSize = 52; // Excludes the hidden bit.
49
+ static const int kSignificandSize = 53;
50
+
51
+ Double() : d64_(0) {}
52
+ explicit Double(double d) : d64_(double_to_uint64(d)) {}
53
+ explicit Double(uint64_t d64) : d64_(d64) {}
54
+ explicit Double(DiyFp diy_fp)
55
+ : d64_(DiyFpToUint64(diy_fp)) {}
56
+
57
+ // The value encoded by this Double must be greater or equal to +0.0.
58
+ // It must not be special (infinity, or NaN).
59
+ DiyFp AsDiyFp() const {
60
+ ASSERT(Sign() > 0);
61
+ ASSERT(!IsSpecial());
62
+ return DiyFp(Significand(), Exponent());
63
+ }
64
+
65
+ // The value encoded by this Double must be strictly greater than 0.
66
+ DiyFp AsNormalizedDiyFp() const {
67
+ ASSERT(value() > 0.0);
68
+ uint64_t f = Significand();
69
+ int e = Exponent();
70
+
71
+ // The current double could be a denormal.
72
+ while ((f & kHiddenBit) == 0) {
73
+ f <<= 1;
74
+ e--;
75
+ }
76
+ // Do the final shifts in one go.
77
+ f <<= DiyFp::kSignificandSize - kSignificandSize;
78
+ e -= DiyFp::kSignificandSize - kSignificandSize;
79
+ return DiyFp(f, e);
80
+ }
81
+
82
+ // Returns the double's bit as uint64.
83
+ uint64_t AsUint64() const {
84
+ return d64_;
85
+ }
86
+
87
+ // Returns the next greater double. Returns +infinity on input +infinity.
88
+ double NextDouble() const {
89
+ if (d64_ == kInfinity) return Double(kInfinity).value();
90
+ if (Sign() < 0 && Significand() == 0) {
91
+ // -0.0
92
+ return 0.0;
93
+ }
94
+ if (Sign() < 0) {
95
+ return Double(d64_ - 1).value();
96
+ } else {
97
+ return Double(d64_ + 1).value();
98
+ }
99
+ }
100
+
101
+ double PreviousDouble() const {
102
+ if (d64_ == (kInfinity | kSignMask)) return -Double::Infinity();
103
+ if (Sign() < 0) {
104
+ return Double(d64_ + 1).value();
105
+ } else {
106
+ if (Significand() == 0) return -0.0;
107
+ return Double(d64_ - 1).value();
108
+ }
109
+ }
110
+
111
+ int Exponent() const {
112
+ if (IsDenormal()) return kDenormalExponent;
113
+
114
+ uint64_t d64 = AsUint64();
115
+ int biased_e =
116
+ static_cast<int>((d64 & kExponentMask) >> kPhysicalSignificandSize);
117
+ return biased_e - kExponentBias;
118
+ }
119
+
120
+ uint64_t Significand() const {
121
+ uint64_t d64 = AsUint64();
122
+ uint64_t significand = d64 & kSignificandMask;
123
+ if (!IsDenormal()) {
124
+ return significand + kHiddenBit;
125
+ } else {
126
+ return significand;
127
+ }
128
+ }
129
+
130
+ // Returns true if the double is a denormal.
131
+ bool IsDenormal() const {
132
+ uint64_t d64 = AsUint64();
133
+ return (d64 & kExponentMask) == 0;
134
+ }
135
+
136
+ // We consider denormals not to be special.
137
+ // Hence only Infinity and NaN are special.
138
+ bool IsSpecial() const {
139
+ uint64_t d64 = AsUint64();
140
+ return (d64 & kExponentMask) == kExponentMask;
141
+ }
142
+
143
+ bool IsNan() const {
144
+ uint64_t d64 = AsUint64();
145
+ return ((d64 & kExponentMask) == kExponentMask) &&
146
+ ((d64 & kSignificandMask) != 0);
147
+ }
148
+
149
+ bool IsInfinite() const {
150
+ uint64_t d64 = AsUint64();
151
+ return ((d64 & kExponentMask) == kExponentMask) &&
152
+ ((d64 & kSignificandMask) == 0);
153
+ }
154
+
155
+ int Sign() const {
156
+ uint64_t d64 = AsUint64();
157
+ return (d64 & kSignMask) == 0? 1: -1;
158
+ }
159
+
160
+ // Precondition: the value encoded by this Double must be greater or equal
161
+ // than +0.0.
162
+ DiyFp UpperBoundary() const {
163
+ ASSERT(Sign() > 0);
164
+ return DiyFp(Significand() * 2 + 1, Exponent() - 1);
165
+ }
166
+
167
+ // Computes the two boundaries of this.
168
+ // The bigger boundary (m_plus) is normalized. The lower boundary has the same
169
+ // exponent as m_plus.
170
+ // Precondition: the value encoded by this Double must be greater than 0.
171
+ void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const {
172
+ ASSERT(value() > 0.0);
173
+ DiyFp v = this->AsDiyFp();
174
+ DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1));
175
+ DiyFp m_minus;
176
+ if (LowerBoundaryIsCloser()) {
177
+ m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2);
178
+ } else {
179
+ m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1);
180
+ }
181
+ m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e()));
182
+ m_minus.set_e(m_plus.e());
183
+ *out_m_plus = m_plus;
184
+ *out_m_minus = m_minus;
185
+ }
186
+
187
+ bool LowerBoundaryIsCloser() const {
188
+ // The boundary is closer if the significand is of the form f == 2^p-1 then
189
+ // the lower boundary is closer.
190
+ // Think of v = 1000e10 and v- = 9999e9.
191
+ // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but
192
+ // at a distance of 1e8.
193
+ // The only exception is for the smallest normal: the largest denormal is
194
+ // at the same distance as its successor.
195
+ // Note: denormals have the same exponent as the smallest normals.
196
+ bool physical_significand_is_zero = ((AsUint64() & kSignificandMask) == 0);
197
+ return physical_significand_is_zero && (Exponent() != kDenormalExponent);
198
+ }
199
+
200
+ double value() const { return uint64_to_double(d64_); }
201
+
202
+ // Returns the significand size for a given order of magnitude.
203
+ // If v = f*2^e with 2^p-1 <= f <= 2^p then p+e is v's order of magnitude.
204
+ // This function returns the number of significant binary digits v will have
205
+ // once it's encoded into a double. In almost all cases this is equal to
206
+ // kSignificandSize. The only exceptions are denormals. They start with
207
+ // leading zeroes and their effective significand-size is hence smaller.
208
+ static int SignificandSizeForOrderOfMagnitude(int order) {
209
+ if (order >= (kDenormalExponent + kSignificandSize)) {
210
+ return kSignificandSize;
211
+ }
212
+ if (order <= kDenormalExponent) return 0;
213
+ return order - kDenormalExponent;
214
+ }
215
+
216
+ static double Infinity() {
217
+ return Double(kInfinity).value();
218
+ }
219
+
220
+ static double NaN() {
221
+ return Double(kNaN).value();
222
+ }
223
+
224
+ private:
225
+ static const int kExponentBias = 0x3FF + kPhysicalSignificandSize;
226
+ static const int kDenormalExponent = -kExponentBias + 1;
227
+ static const int kMaxExponent = 0x7FF - kExponentBias;
228
+ static const uint64_t kInfinity = UINT64_2PART_C(0x7FF00000, 00000000);
229
+ static const uint64_t kNaN = UINT64_2PART_C(0x7FF80000, 00000000);
230
+
231
+ const uint64_t d64_;
232
+
233
+ static uint64_t DiyFpToUint64(DiyFp diy_fp) {
234
+ uint64_t significand = diy_fp.f();
235
+ int exponent = diy_fp.e();
236
+ while (significand > kHiddenBit + kSignificandMask) {
237
+ significand >>= 1;
238
+ exponent++;
239
+ }
240
+ if (exponent >= kMaxExponent) {
241
+ return kInfinity;
242
+ }
243
+ if (exponent < kDenormalExponent) {
244
+ return 0;
245
+ }
246
+ while (exponent > kDenormalExponent && (significand & kHiddenBit) == 0) {
247
+ significand <<= 1;
248
+ exponent--;
249
+ }
250
+ uint64_t biased_exponent;
251
+ if (exponent == kDenormalExponent && (significand & kHiddenBit) == 0) {
252
+ biased_exponent = 0;
253
+ } else {
254
+ biased_exponent = static_cast<uint64_t>(exponent + kExponentBias);
255
+ }
256
+ return (significand & kSignificandMask) |
257
+ (biased_exponent << kPhysicalSignificandSize);
258
+ }
259
+
260
+ DISALLOW_COPY_AND_ASSIGN(Double);
261
+ };
262
+
263
+ class Single {
264
+ public:
265
+ static const uint32_t kSignMask = 0x80000000;
266
+ static const uint32_t kExponentMask = 0x7F800000;
267
+ static const uint32_t kSignificandMask = 0x007FFFFF;
268
+ static const uint32_t kHiddenBit = 0x00800000;
269
+ static const int kPhysicalSignificandSize = 23; // Excludes the hidden bit.
270
+ static const int kSignificandSize = 24;
271
+
272
+ Single() : d32_(0) {}
273
+ explicit Single(float f) : d32_(float_to_uint32(f)) {}
274
+ explicit Single(uint32_t d32) : d32_(d32) {}
275
+
276
+ // The value encoded by this Single must be greater or equal to +0.0.
277
+ // It must not be special (infinity, or NaN).
278
+ DiyFp AsDiyFp() const {
279
+ ASSERT(Sign() > 0);
280
+ ASSERT(!IsSpecial());
281
+ return DiyFp(Significand(), Exponent());
282
+ }
283
+
284
+ // Returns the single's bit as uint64.
285
+ uint32_t AsUint32() const {
286
+ return d32_;
287
+ }
288
+
289
+ int Exponent() const {
290
+ if (IsDenormal()) return kDenormalExponent;
291
+
292
+ uint32_t d32 = AsUint32();
293
+ int biased_e =
294
+ static_cast<int>((d32 & kExponentMask) >> kPhysicalSignificandSize);
295
+ return biased_e - kExponentBias;
296
+ }
297
+
298
+ uint32_t Significand() const {
299
+ uint32_t d32 = AsUint32();
300
+ uint32_t significand = d32 & kSignificandMask;
301
+ if (!IsDenormal()) {
302
+ return significand + kHiddenBit;
303
+ } else {
304
+ return significand;
305
+ }
306
+ }
307
+
308
+ // Returns true if the single is a denormal.
309
+ bool IsDenormal() const {
310
+ uint32_t d32 = AsUint32();
311
+ return (d32 & kExponentMask) == 0;
312
+ }
313
+
314
+ // We consider denormals not to be special.
315
+ // Hence only Infinity and NaN are special.
316
+ bool IsSpecial() const {
317
+ uint32_t d32 = AsUint32();
318
+ return (d32 & kExponentMask) == kExponentMask;
319
+ }
320
+
321
+ bool IsNan() const {
322
+ uint32_t d32 = AsUint32();
323
+ return ((d32 & kExponentMask) == kExponentMask) &&
324
+ ((d32 & kSignificandMask) != 0);
325
+ }
326
+
327
+ bool IsInfinite() const {
328
+ uint32_t d32 = AsUint32();
329
+ return ((d32 & kExponentMask) == kExponentMask) &&
330
+ ((d32 & kSignificandMask) == 0);
331
+ }
332
+
333
+ int Sign() const {
334
+ uint32_t d32 = AsUint32();
335
+ return (d32 & kSignMask) == 0? 1: -1;
336
+ }
337
+
338
+ // Computes the two boundaries of this.
339
+ // The bigger boundary (m_plus) is normalized. The lower boundary has the same
340
+ // exponent as m_plus.
341
+ // Precondition: the value encoded by this Single must be greater than 0.
342
+ void NormalizedBoundaries(DiyFp* out_m_minus, DiyFp* out_m_plus) const {
343
+ ASSERT(value() > 0.0);
344
+ DiyFp v = this->AsDiyFp();
345
+ DiyFp m_plus = DiyFp::Normalize(DiyFp((v.f() << 1) + 1, v.e() - 1));
346
+ DiyFp m_minus;
347
+ if (LowerBoundaryIsCloser()) {
348
+ m_minus = DiyFp((v.f() << 2) - 1, v.e() - 2);
349
+ } else {
350
+ m_minus = DiyFp((v.f() << 1) - 1, v.e() - 1);
351
+ }
352
+ m_minus.set_f(m_minus.f() << (m_minus.e() - m_plus.e()));
353
+ m_minus.set_e(m_plus.e());
354
+ *out_m_plus = m_plus;
355
+ *out_m_minus = m_minus;
356
+ }
357
+
358
+ // Precondition: the value encoded by this Single must be greater or equal
359
+ // than +0.0.
360
+ DiyFp UpperBoundary() const {
361
+ ASSERT(Sign() > 0);
362
+ return DiyFp(Significand() * 2 + 1, Exponent() - 1);
363
+ }
364
+
365
+ bool LowerBoundaryIsCloser() const {
366
+ // The boundary is closer if the significand is of the form f == 2^p-1 then
367
+ // the lower boundary is closer.
368
+ // Think of v = 1000e10 and v- = 9999e9.
369
+ // Then the boundary (== (v - v-)/2) is not just at a distance of 1e9 but
370
+ // at a distance of 1e8.
371
+ // The only exception is for the smallest normal: the largest denormal is
372
+ // at the same distance as its successor.
373
+ // Note: denormals have the same exponent as the smallest normals.
374
+ bool physical_significand_is_zero = ((AsUint32() & kSignificandMask) == 0);
375
+ return physical_significand_is_zero && (Exponent() != kDenormalExponent);
376
+ }
377
+
378
+ float value() const { return uint32_to_float(d32_); }
379
+
380
+ static float Infinity() {
381
+ return Single(kInfinity).value();
382
+ }
383
+
384
+ static float NaN() {
385
+ return Single(kNaN).value();
386
+ }
387
+
388
+ private:
389
+ static const int kExponentBias = 0x7F + kPhysicalSignificandSize;
390
+ static const int kDenormalExponent = -kExponentBias + 1;
391
+ static const int kMaxExponent = 0xFF - kExponentBias;
392
+ static const uint32_t kInfinity = 0x7F800000;
393
+ static const uint32_t kNaN = 0x7FC00000;
394
+
395
+ const uint32_t d32_;
396
+
397
+ DISALLOW_COPY_AND_ASSIGN(Single);
398
+ };
399
+
400
+ } // namespace double_conversion
401
+
402
+ #endif // DOUBLE_CONVERSION_DOUBLE_H_