usearch 2.10.2 → 2.10.5
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.
- package/README.md +1 -1
- package/binding.gyp +101 -0
- package/c/CMakeLists.txt +27 -0
- package/c/README.md +34 -0
- package/c/lib.cpp +362 -0
- package/c/test.c +382 -0
- package/c/usearch.h +356 -0
- package/cmake/clipp.cmake +7 -0
- package/cmake/config.cmake.in +15 -0
- package/cmake/emscripten.cmake +8 -0
- package/cmake/jemalloc.cmake +62 -0
- package/cmake/pkg-config.pc.in +4 -0
- package/cmake/usearchConfigVersion.cmake.in +20 -0
- package/cpp/CMakeLists.txt +14 -0
- package/cpp/README.md +161 -0
- package/cpp/bench.cpp +616 -0
- package/cpp/test.cpp +324 -0
- package/fp16/CMakeLists.txt +176 -0
- package/fp16/LICENSE +11 -0
- package/fp16/README.md +20 -0
- package/fp16/bench/alt-element.cc +89 -0
- package/fp16/bench/from-alt-array.cc +175 -0
- package/fp16/bench/from-ieee-array.cc +399 -0
- package/fp16/bench/ieee-element.cc +272 -0
- package/fp16/bench/to-alt-array.cc +91 -0
- package/fp16/bench/to-ieee-array.cc +303 -0
- package/fp16/cmake/DownloadGoogleBenchmark.cmake +15 -0
- package/fp16/cmake/DownloadGoogleTest.cmake +15 -0
- package/fp16/cmake/DownloadPSimd.cmake +15 -0
- package/fp16/configure.py +65 -0
- package/fp16/confu.yaml +8 -0
- package/fp16/include/fp16/__init__.py +0 -0
- package/fp16/include/fp16/avx.py +50 -0
- package/fp16/include/fp16/avx2.py +53 -0
- package/fp16/include/fp16/bitcasts.h +92 -0
- package/fp16/include/fp16/fp16.h +451 -0
- package/fp16/include/fp16/psimd.h +131 -0
- package/fp16/include/fp16.h +11 -0
- package/fp16/jni/Android.mk +6 -0
- package/fp16/jni/Application.mk +4 -0
- package/fp16/test/alt-from-fp32-value.cc +498 -0
- package/fp16/test/alt-to-fp32-bits.cc +263 -0
- package/fp16/test/alt-to-fp32-psimd.cc +145 -0
- package/fp16/test/alt-to-fp32-value.cc +348 -0
- package/fp16/test/alt-to-fp32x2-psimd.cc +245 -0
- package/fp16/test/bitcasts.cc +56 -0
- package/fp16/test/ieee-from-fp32-value.cc +523 -0
- package/fp16/test/ieee-to-fp32-bits.cc +333 -0
- package/fp16/test/ieee-to-fp32-psimd.cc +312 -0
- package/fp16/test/ieee-to-fp32-value.cc +420 -0
- package/fp16/test/ieee-to-fp32x2-psimd.cc +541 -0
- package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +96 -0
- package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +96 -0
- package/fp16/test/peachpy/stubs.py +38 -0
- package/fp16/test/tables.cc +530 -0
- package/fp16/test/tables.h +13 -0
- package/fp16/third-party/THHalf.h +92 -0
- package/fp16/third-party/eigen-half.h +170 -0
- package/fp16/third-party/float16-compressor.h +80 -0
- package/fp16/third-party/half.hpp +2916 -0
- package/fp16/third-party/npy-halffloat.h +328 -0
- package/include/usearch/index.hpp +3838 -0
- package/include/usearch/index_dense.hpp +2004 -0
- package/include/usearch/index_plugins.hpp +2255 -0
- package/javascript/dist-package-cjs.json +3 -0
- package/javascript/dist-package-esm.json +3 -0
- package/javascript/lib.cpp +350 -0
- package/javascript/node-gyp-build.d.ts +1 -0
- package/javascript/tsconfig-base.json +25 -0
- package/javascript/tsconfig-cjs.json +8 -0
- package/javascript/tsconfig-esm.json +8 -0
- package/javascript/usearch.test.js +84 -0
- package/javascript/usearch.ts +640 -0
- package/package.json +10 -3
- package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
- package/prebuilds/linux-arm64/usearch.node +0 -0
- package/prebuilds/linux-x64/usearch.node +0 -0
- package/prebuilds/win32-ia32/usearch.node +0 -0
- package/prebuilds/win32-x64/usearch.node +0 -0
- package/simsimd/.releaserc +87 -0
- package/simsimd/CONTRIBUTING.md +114 -0
- package/simsimd/Cargo.lock +709 -0
- package/simsimd/Cargo.toml +44 -0
- package/simsimd/LICENSE +201 -0
- package/simsimd/README.md +708 -0
- package/simsimd/binding.gyp +36 -0
- package/simsimd/build.rs +51 -0
- package/simsimd/c/lib.c +110 -0
- package/simsimd/include/simsimd/binary.h +258 -0
- package/simsimd/include/simsimd/dot.h +1237 -0
- package/simsimd/include/simsimd/geospatial.h +37 -0
- package/simsimd/include/simsimd/probability.h +563 -0
- package/simsimd/include/simsimd/simsimd.h +1129 -0
- package/simsimd/include/simsimd/spatial.h +1019 -0
- package/simsimd/include/simsimd/types.h +309 -0
- package/simsimd/javascript/bench.js +127 -0
- package/simsimd/javascript/dist-package-cjs.json +3 -0
- package/simsimd/javascript/dist-package-esm.json +3 -0
- package/simsimd/javascript/fallback.ts +203 -0
- package/simsimd/javascript/lib.c +107 -0
- package/simsimd/javascript/node-gyp-build.d.ts +1 -0
- package/simsimd/javascript/simsimd.ts +135 -0
- package/simsimd/javascript/test.mjs +179 -0
- package/simsimd/javascript/tsconfig-base.json +37 -0
- package/simsimd/javascript/tsconfig-cjs.json +8 -0
- package/simsimd/javascript/tsconfig-esm.json +8 -0
- package/simsimd/package-lock.json +1709 -0
- package/simsimd/package.json +61 -0
- package/simsimd/rust/benches/cosine.rs +27 -0
- package/simsimd/rust/benches/native.rs +30 -0
- package/simsimd/rust/benches/sqeuclidean.rs +27 -0
- package/simsimd/rust/lib.rs +778 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This implementation is extracted from numpy:
|
|
3
|
+
* Repo: github.com/numpy/numpy
|
|
4
|
+
* File: numpy/core/src/npymath/halffloat.c
|
|
5
|
+
* Commit ID: 25c23f1d956104a072a95355ffaa7a38b53710b7
|
|
6
|
+
* Functions are made "static inline" for performance, and
|
|
7
|
+
* non-conversion functions are removed, and generation of
|
|
8
|
+
* exceptions is disabled.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
typedef uint16_t npy_uint16;
|
|
13
|
+
typedef uint32_t npy_uint32;
|
|
14
|
+
typedef uint64_t npy_uint64;
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* This chooses between 'ties to even' and 'ties away from zero'.
|
|
18
|
+
*/
|
|
19
|
+
#define NPY_HALF_ROUND_TIES_TO_EVEN 1
|
|
20
|
+
/*
|
|
21
|
+
* If these are 1, the conversions try to trigger underflow,
|
|
22
|
+
* overflow, and invalid exceptions in the FP system when needed.
|
|
23
|
+
*/
|
|
24
|
+
#define NPY_HALF_GENERATE_OVERFLOW 0
|
|
25
|
+
#define NPY_HALF_GENERATE_UNDERFLOW 0
|
|
26
|
+
#define NPY_HALF_GENERATE_INVALID 0
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
********************************************************************
|
|
30
|
+
* BIT-LEVEL CONVERSIONS *
|
|
31
|
+
********************************************************************
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
static inline npy_uint16 npy_floatbits_to_halfbits(npy_uint32 f)
|
|
35
|
+
{
|
|
36
|
+
npy_uint32 f_exp, f_sig;
|
|
37
|
+
npy_uint16 h_sgn, h_exp, h_sig;
|
|
38
|
+
|
|
39
|
+
h_sgn = (npy_uint16) ((f&0x80000000u) >> 16);
|
|
40
|
+
f_exp = (f&0x7f800000u);
|
|
41
|
+
|
|
42
|
+
/* Exponent overflow/NaN converts to signed inf/NaN */
|
|
43
|
+
if (f_exp >= 0x47800000u) {
|
|
44
|
+
if (f_exp == 0x7f800000u) {
|
|
45
|
+
/* Inf or NaN */
|
|
46
|
+
f_sig = (f&0x007fffffu);
|
|
47
|
+
if (f_sig != 0) {
|
|
48
|
+
/* NaN - propagate the flag in the significand... */
|
|
49
|
+
npy_uint16 ret = (npy_uint16) (0x7c00u + (f_sig >> 13));
|
|
50
|
+
/* ...but make sure it stays a NaN */
|
|
51
|
+
if (ret == 0x7c00u) {
|
|
52
|
+
ret++;
|
|
53
|
+
}
|
|
54
|
+
return h_sgn + ret;
|
|
55
|
+
} else {
|
|
56
|
+
/* signed inf */
|
|
57
|
+
return (npy_uint16) (h_sgn + 0x7c00u);
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
/* overflow to signed inf */
|
|
61
|
+
#if NPY_HALF_GENERATE_OVERFLOW
|
|
62
|
+
npy_set_floatstatus_overflow();
|
|
63
|
+
#endif
|
|
64
|
+
return (npy_uint16) (h_sgn + 0x7c00u);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* Exponent underflow converts to a subnormal half or signed zero */
|
|
69
|
+
if (f_exp <= 0x38000000u) {
|
|
70
|
+
/*
|
|
71
|
+
* Signed zeros, subnormal floats, and floats with small
|
|
72
|
+
* exponents all convert to signed zero halfs.
|
|
73
|
+
*/
|
|
74
|
+
if (f_exp < 0x33000000u) {
|
|
75
|
+
#if NPY_HALF_GENERATE_UNDERFLOW
|
|
76
|
+
/* If f != 0, it underflowed to 0 */
|
|
77
|
+
if ((f&0x7fffffff) != 0) {
|
|
78
|
+
npy_set_floatstatus_underflow();
|
|
79
|
+
}
|
|
80
|
+
#endif
|
|
81
|
+
return h_sgn;
|
|
82
|
+
}
|
|
83
|
+
/* Make the subnormal significand */
|
|
84
|
+
f_exp >>= 23;
|
|
85
|
+
f_sig = (0x00800000u + (f&0x007fffffu));
|
|
86
|
+
#if NPY_HALF_GENERATE_UNDERFLOW
|
|
87
|
+
/* If it's not exactly represented, it underflowed */
|
|
88
|
+
if ((f_sig&(((npy_uint32)1 << (126 - f_exp)) - 1)) != 0) {
|
|
89
|
+
npy_set_floatstatus_underflow();
|
|
90
|
+
}
|
|
91
|
+
#endif
|
|
92
|
+
f_sig >>= (113 - f_exp);
|
|
93
|
+
/* Handle rounding by adding 1 to the bit beyond half precision */
|
|
94
|
+
#if NPY_HALF_ROUND_TIES_TO_EVEN
|
|
95
|
+
/*
|
|
96
|
+
* If the last bit in the half significand is 0 (already even), and
|
|
97
|
+
* the remaining bit pattern is 1000...0, then we do not add one
|
|
98
|
+
* to the bit after the half significand. In all other cases, we do.
|
|
99
|
+
*/
|
|
100
|
+
if ((f_sig&0x00003fffu) != 0x00001000u) {
|
|
101
|
+
f_sig += 0x00001000u;
|
|
102
|
+
}
|
|
103
|
+
#else
|
|
104
|
+
f_sig += 0x00001000u;
|
|
105
|
+
#endif
|
|
106
|
+
h_sig = (npy_uint16) (f_sig >> 13);
|
|
107
|
+
/*
|
|
108
|
+
* If the rounding causes a bit to spill into h_exp, it will
|
|
109
|
+
* increment h_exp from zero to one and h_sig will be zero.
|
|
110
|
+
* This is the correct result.
|
|
111
|
+
*/
|
|
112
|
+
return (npy_uint16) (h_sgn + h_sig);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* Regular case with no overflow or underflow */
|
|
116
|
+
h_exp = (npy_uint16) ((f_exp - 0x38000000u) >> 13);
|
|
117
|
+
/* Handle rounding by adding 1 to the bit beyond half precision */
|
|
118
|
+
f_sig = (f&0x007fffffu);
|
|
119
|
+
#if NPY_HALF_ROUND_TIES_TO_EVEN
|
|
120
|
+
/*
|
|
121
|
+
* If the last bit in the half significand is 0 (already even), and
|
|
122
|
+
* the remaining bit pattern is 1000...0, then we do not add one
|
|
123
|
+
* to the bit after the half significand. In all other cases, we do.
|
|
124
|
+
*/
|
|
125
|
+
if ((f_sig&0x00003fffu) != 0x00001000u) {
|
|
126
|
+
f_sig += 0x00001000u;
|
|
127
|
+
}
|
|
128
|
+
#else
|
|
129
|
+
f_sig += 0x00001000u;
|
|
130
|
+
#endif
|
|
131
|
+
h_sig = (npy_uint16) (f_sig >> 13);
|
|
132
|
+
/*
|
|
133
|
+
* If the rounding causes a bit to spill into h_exp, it will
|
|
134
|
+
* increment h_exp by one and h_sig will be zero. This is the
|
|
135
|
+
* correct result. h_exp may increment to 15, at greatest, in
|
|
136
|
+
* which case the result overflows to a signed inf.
|
|
137
|
+
*/
|
|
138
|
+
#if NPY_HALF_GENERATE_OVERFLOW
|
|
139
|
+
h_sig += h_exp;
|
|
140
|
+
if (h_sig == 0x7c00u) {
|
|
141
|
+
npy_set_floatstatus_overflow();
|
|
142
|
+
}
|
|
143
|
+
return h_sgn + h_sig;
|
|
144
|
+
#else
|
|
145
|
+
return h_sgn + h_exp + h_sig;
|
|
146
|
+
#endif
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static inline npy_uint16 npy_doublebits_to_halfbits(npy_uint64 d)
|
|
150
|
+
{
|
|
151
|
+
npy_uint64 d_exp, d_sig;
|
|
152
|
+
npy_uint16 h_sgn, h_exp, h_sig;
|
|
153
|
+
|
|
154
|
+
h_sgn = (d&0x8000000000000000ULL) >> 48;
|
|
155
|
+
d_exp = (d&0x7ff0000000000000ULL);
|
|
156
|
+
|
|
157
|
+
/* Exponent overflow/NaN converts to signed inf/NaN */
|
|
158
|
+
if (d_exp >= 0x40f0000000000000ULL) {
|
|
159
|
+
if (d_exp == 0x7ff0000000000000ULL) {
|
|
160
|
+
/* Inf or NaN */
|
|
161
|
+
d_sig = (d&0x000fffffffffffffULL);
|
|
162
|
+
if (d_sig != 0) {
|
|
163
|
+
/* NaN - propagate the flag in the significand... */
|
|
164
|
+
npy_uint16 ret = (npy_uint16) (0x7c00u + (d_sig >> 42));
|
|
165
|
+
/* ...but make sure it stays a NaN */
|
|
166
|
+
if (ret == 0x7c00u) {
|
|
167
|
+
ret++;
|
|
168
|
+
}
|
|
169
|
+
return h_sgn + ret;
|
|
170
|
+
} else {
|
|
171
|
+
/* signed inf */
|
|
172
|
+
return h_sgn + 0x7c00u;
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
/* overflow to signed inf */
|
|
176
|
+
#if NPY_HALF_GENERATE_OVERFLOW
|
|
177
|
+
npy_set_floatstatus_overflow();
|
|
178
|
+
#endif
|
|
179
|
+
return h_sgn + 0x7c00u;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/* Exponent underflow converts to subnormal half or signed zero */
|
|
184
|
+
if (d_exp <= 0x3f00000000000000ULL) {
|
|
185
|
+
/*
|
|
186
|
+
* Signed zeros, subnormal floats, and floats with small
|
|
187
|
+
* exponents all convert to signed zero halfs.
|
|
188
|
+
*/
|
|
189
|
+
if (d_exp < 0x3e60000000000000ULL) {
|
|
190
|
+
#if NPY_HALF_GENERATE_UNDERFLOW
|
|
191
|
+
/* If d != 0, it underflowed to 0 */
|
|
192
|
+
if ((d&0x7fffffffffffffffULL) != 0) {
|
|
193
|
+
npy_set_floatstatus_underflow();
|
|
194
|
+
}
|
|
195
|
+
#endif
|
|
196
|
+
return h_sgn;
|
|
197
|
+
}
|
|
198
|
+
/* Make the subnormal significand */
|
|
199
|
+
d_exp >>= 52;
|
|
200
|
+
d_sig = (0x0010000000000000ULL + (d&0x000fffffffffffffULL));
|
|
201
|
+
#if NPY_HALF_GENERATE_UNDERFLOW
|
|
202
|
+
/* If it's not exactly represented, it underflowed */
|
|
203
|
+
if ((d_sig&(((npy_uint64)1 << (1051 - d_exp)) - 1)) != 0) {
|
|
204
|
+
npy_set_floatstatus_underflow();
|
|
205
|
+
}
|
|
206
|
+
#endif
|
|
207
|
+
d_sig >>= (1009 - d_exp);
|
|
208
|
+
/* Handle rounding by adding 1 to the bit beyond half precision */
|
|
209
|
+
#if NPY_HALF_ROUND_TIES_TO_EVEN
|
|
210
|
+
/*
|
|
211
|
+
* If the last bit in the half significand is 0 (already even), and
|
|
212
|
+
* the remaining bit pattern is 1000...0, then we do not add one
|
|
213
|
+
* to the bit after the half significand. In all other cases, we do.
|
|
214
|
+
*/
|
|
215
|
+
if ((d_sig&0x000007ffffffffffULL) != 0x0000020000000000ULL) {
|
|
216
|
+
d_sig += 0x0000020000000000ULL;
|
|
217
|
+
}
|
|
218
|
+
#else
|
|
219
|
+
d_sig += 0x0000020000000000ULL;
|
|
220
|
+
#endif
|
|
221
|
+
h_sig = (npy_uint16) (d_sig >> 42);
|
|
222
|
+
/*
|
|
223
|
+
* If the rounding causes a bit to spill into h_exp, it will
|
|
224
|
+
* increment h_exp from zero to one and h_sig will be zero.
|
|
225
|
+
* This is the correct result.
|
|
226
|
+
*/
|
|
227
|
+
return h_sgn + h_sig;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/* Regular case with no overflow or underflow */
|
|
231
|
+
h_exp = (npy_uint16) ((d_exp - 0x3f00000000000000ULL) >> 42);
|
|
232
|
+
/* Handle rounding by adding 1 to the bit beyond half precision */
|
|
233
|
+
d_sig = (d&0x000fffffffffffffULL);
|
|
234
|
+
#if NPY_HALF_ROUND_TIES_TO_EVEN
|
|
235
|
+
/*
|
|
236
|
+
* If the last bit in the half significand is 0 (already even), and
|
|
237
|
+
* the remaining bit pattern is 1000...0, then we do not add one
|
|
238
|
+
* to the bit after the half significand. In all other cases, we do.
|
|
239
|
+
*/
|
|
240
|
+
if ((d_sig&0x000007ffffffffffULL) != 0x0000020000000000ULL) {
|
|
241
|
+
d_sig += 0x0000020000000000ULL;
|
|
242
|
+
}
|
|
243
|
+
#else
|
|
244
|
+
d_sig += 0x0000020000000000ULL;
|
|
245
|
+
#endif
|
|
246
|
+
h_sig = (npy_uint16) (d_sig >> 42);
|
|
247
|
+
|
|
248
|
+
/*
|
|
249
|
+
* If the rounding causes a bit to spill into h_exp, it will
|
|
250
|
+
* increment h_exp by one and h_sig will be zero. This is the
|
|
251
|
+
* correct result. h_exp may increment to 15, at greatest, in
|
|
252
|
+
* which case the result overflows to a signed inf.
|
|
253
|
+
*/
|
|
254
|
+
#if NPY_HALF_GENERATE_OVERFLOW
|
|
255
|
+
h_sig += h_exp;
|
|
256
|
+
if (h_sig == 0x7c00u) {
|
|
257
|
+
npy_set_floatstatus_overflow();
|
|
258
|
+
}
|
|
259
|
+
return h_sgn + h_sig;
|
|
260
|
+
#else
|
|
261
|
+
return h_sgn + h_exp + h_sig;
|
|
262
|
+
#endif
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
static inline npy_uint32 npy_halfbits_to_floatbits(npy_uint16 h)
|
|
266
|
+
{
|
|
267
|
+
npy_uint16 h_exp, h_sig;
|
|
268
|
+
npy_uint32 f_sgn, f_exp, f_sig;
|
|
269
|
+
|
|
270
|
+
h_exp = (h&0x7c00u);
|
|
271
|
+
f_sgn = ((npy_uint32)h&0x8000u) << 16;
|
|
272
|
+
switch (h_exp) {
|
|
273
|
+
case 0x0000u: /* 0 or subnormal */
|
|
274
|
+
h_sig = (h&0x03ffu);
|
|
275
|
+
/* Signed zero */
|
|
276
|
+
if (h_sig == 0) {
|
|
277
|
+
return f_sgn;
|
|
278
|
+
}
|
|
279
|
+
/* Subnormal */
|
|
280
|
+
h_sig <<= 1;
|
|
281
|
+
while ((h_sig&0x0400u) == 0) {
|
|
282
|
+
h_sig <<= 1;
|
|
283
|
+
h_exp++;
|
|
284
|
+
}
|
|
285
|
+
f_exp = ((npy_uint32)(127 - 15 - h_exp)) << 23;
|
|
286
|
+
f_sig = ((npy_uint32)(h_sig&0x03ffu)) << 13;
|
|
287
|
+
return f_sgn + f_exp + f_sig;
|
|
288
|
+
case 0x7c00u: /* inf or NaN */
|
|
289
|
+
/* All-ones exponent and a copy of the significand */
|
|
290
|
+
return f_sgn + 0x7f800000u + (((npy_uint32)(h&0x03ffu)) << 13);
|
|
291
|
+
default: /* normalized */
|
|
292
|
+
/* Just need to adjust the exponent and shift */
|
|
293
|
+
return f_sgn + (((npy_uint32)(h&0x7fffu) + 0x1c000u) << 13);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
static inline npy_uint64 npy_halfbits_to_doublebits(npy_uint16 h)
|
|
298
|
+
{
|
|
299
|
+
npy_uint16 h_exp, h_sig;
|
|
300
|
+
npy_uint64 d_sgn, d_exp, d_sig;
|
|
301
|
+
|
|
302
|
+
h_exp = (h&0x7c00u);
|
|
303
|
+
d_sgn = ((npy_uint64)h&0x8000u) << 48;
|
|
304
|
+
switch (h_exp) {
|
|
305
|
+
case 0x0000u: /* 0 or subnormal */
|
|
306
|
+
h_sig = (h&0x03ffu);
|
|
307
|
+
/* Signed zero */
|
|
308
|
+
if (h_sig == 0) {
|
|
309
|
+
return d_sgn;
|
|
310
|
+
}
|
|
311
|
+
/* Subnormal */
|
|
312
|
+
h_sig <<= 1;
|
|
313
|
+
while ((h_sig&0x0400u) == 0) {
|
|
314
|
+
h_sig <<= 1;
|
|
315
|
+
h_exp++;
|
|
316
|
+
}
|
|
317
|
+
d_exp = ((npy_uint64)(1023 - 15 - h_exp)) << 52;
|
|
318
|
+
d_sig = ((npy_uint64)(h_sig&0x03ffu)) << 42;
|
|
319
|
+
return d_sgn + d_exp + d_sig;
|
|
320
|
+
case 0x7c00u: /* inf or NaN */
|
|
321
|
+
/* All-ones exponent and a copy of the significand */
|
|
322
|
+
return d_sgn + 0x7ff0000000000000ULL +
|
|
323
|
+
(((npy_uint64)(h&0x03ffu)) << 42);
|
|
324
|
+
default: /* normalized */
|
|
325
|
+
/* Just need to adjust the exponent and shift */
|
|
326
|
+
return d_sgn + (((npy_uint64)(h&0x7fffu) + 0xfc000u) << 42);
|
|
327
|
+
}
|
|
328
|
+
}
|