cbor 0.5.9.9 → 0.5.10.1
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.
- checksums.yaml +4 -4
- data/ext/cbor/packer.h +13 -5
- data/ext/cbor/unpacker.c +23 -4
- data/lib/cbor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 350f51028ed72c54fb5adf9ab595f08e18384cecb8c82d874d195aab6eb16a65
|
4
|
+
data.tar.gz: 1eb340e507d590530f0c2d9a3cfaf723fb9210596a312443e7b2dc95b912614f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30fb71f7d3fce1bbf5f40c84d7ca389a1e30051c186c01553d0be07e784a4029dc27cdf6c01a70dd1a155c6bddd050d21705c642e5df6727633d15b39808d153
|
7
|
+
data.tar.gz: 75783b66fccc0dd03ce323411f81848964e0904805e5eeb9218cc59214d1bfd1a3011df255de2b6a95a92b1d42475d5fb770a0029d6486c6c4060605a3e24f94
|
data/ext/cbor/packer.h
CHANGED
@@ -170,17 +170,25 @@ static inline void msgpack_packer_write_double(msgpack_packer_t* pk, double v)
|
|
170
170
|
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5);
|
171
171
|
castbuf.u32 = _msgpack_be_float(castbuf.u32);
|
172
172
|
msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), IB_FLOAT4, castbuf.mem, 4);
|
173
|
-
} else if (v != v) { /* NaN */
|
174
|
-
cbor_encoder_write_head(pk, 0xe0, 0x7e00);
|
175
173
|
} else {
|
176
|
-
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9);
|
177
174
|
union {
|
178
175
|
double d;
|
179
176
|
uint64_t u64;
|
180
177
|
char mem[8];
|
181
178
|
} castbuf = { v };
|
182
|
-
|
183
|
-
|
179
|
+
if (v != v && (castbuf.u64 & 0x1fffffffUL) == 0) { /* NaN && can narrow */
|
180
|
+
uint64_t sign = castbuf.u64 >> 63;
|
181
|
+
uint64_t mant = castbuf.u64 & 0xfffffffffffff; /* 52 bits */
|
182
|
+
if ((mant & 0x3ffffffffffUL) == 0) { /* 42 zero bits: narrow to f16 */
|
183
|
+
cbor_encoder_write_head(pk, 0xe0, sign << 15 | 0x7c00 | mant >> 42);
|
184
|
+
} else { /* 29 zero bits (checked above): narrow to f32 */
|
185
|
+
cbor_encoder_write_head(pk, 0xe0, sign << 31 | 0x7f800000 | mant >> 29);
|
186
|
+
}
|
187
|
+
} else { /* can't narrow */
|
188
|
+
msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9);
|
189
|
+
castbuf.u64 = _msgpack_be_double(castbuf.u64);
|
190
|
+
msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), IB_FLOAT8, castbuf.mem, 8);
|
191
|
+
}
|
184
192
|
}
|
185
193
|
}
|
186
194
|
|
data/ext/cbor/unpacker.c
CHANGED
@@ -417,11 +417,21 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
417
417
|
switch (ai) {
|
418
418
|
case AI_2: { // half
|
419
419
|
int exp = (val >> 10) & 0x1f;
|
420
|
-
int mant = val & 0x3ff;
|
420
|
+
int mant = val & 0x3ff; /* 10 bits */
|
421
421
|
double res;
|
422
422
|
if (exp == 0) res = ldexp(mant, -24);
|
423
423
|
else if (exp != 31) res = ldexp11(mant + 1024, exp - 25);
|
424
|
-
else
|
424
|
+
else {
|
425
|
+
if (mant == 0)
|
426
|
+
res = INFINITY;
|
427
|
+
else { /* NAN */
|
428
|
+
union {
|
429
|
+
uint64_t u64;
|
430
|
+
double d;
|
431
|
+
} castbuf = { (val & 0x8000) << 48 | 0x7ff0000000000000UL | (uint64_t)mant << 42 };
|
432
|
+
return object_complete(uk, rb_float_new(castbuf.d));
|
433
|
+
}
|
434
|
+
}
|
425
435
|
return object_complete(uk, rb_float_new(val & 0x8000 ? -res : res));
|
426
436
|
}
|
427
437
|
case AI_4: // float
|
@@ -429,8 +439,17 @@ static int read_primitive(msgpack_unpacker_t* uk)
|
|
429
439
|
union {
|
430
440
|
uint32_t u32;
|
431
441
|
float f;
|
432
|
-
} castbuf = { (uint32_t)val };
|
433
|
-
|
442
|
+
} castbuf = { (uint32_t)val }; /* sets Q to 1 for NAN */
|
443
|
+
if (castbuf.f == castbuf.f) {
|
444
|
+
return object_complete(uk, rb_float_new(castbuf.f));
|
445
|
+
} else { /* NAN */
|
446
|
+
uint64_t mant = val & 0x7fffff; /* 23 bits */
|
447
|
+
union {
|
448
|
+
uint64_t u64;
|
449
|
+
double d;
|
450
|
+
} castbuf1 = { (val & 0x80000000UL) << 32 | 0x7ff0000000000000UL | mant << 29 };
|
451
|
+
return object_complete(uk, rb_float_new(castbuf1.d));
|
452
|
+
}
|
434
453
|
}
|
435
454
|
case AI_8: // double
|
436
455
|
{
|
data/lib/cbor/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carsten Bormann, standing on the tall shoulders of Sadayuki Furuhashi
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-08-
|
10
|
+
date: 2025-08-07 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|