ordered-binary
Advanced tools
Comparing version 1.5.0 to 1.5.1
33
index.js
@@ -127,7 +127,16 @@ /* | ||
float64Array[0] = asFloat; | ||
if (int32Array[0]) | ||
int32Array[0]--; | ||
else { | ||
int32Array[1]--; | ||
int32Array[0] = 0xffffffff; | ||
if (asFloat > 0) { | ||
if (int32Array[0]) | ||
int32Array[0]--; | ||
else { | ||
int32Array[1]--; | ||
int32Array[0] = 0xffffffff; | ||
} | ||
} else { | ||
if (int32Array[0] < 0xffffffff) | ||
int32Array[0]++; | ||
else { | ||
int32Array[1]++; | ||
int32Array[0] = 0; | ||
} | ||
} | ||
@@ -141,3 +150,3 @@ asFloat = float64Array[0]; | ||
position += 9; // always increment by 9 if we are adding fractional bits | ||
let exponent = BigInt((int32Array[1] >> 20) - 1079); | ||
let exponent = BigInt((int32Array[1] >> 20 & 0x7ff) - 1079); | ||
let nextByte = difference >> exponent; | ||
@@ -189,3 +198,10 @@ target[position - 1] |= Number(nextByte); | ||
} else { | ||
let dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, ((buffer.byteLength + 3) >> 2) << 2)) | ||
let dataView; | ||
try { | ||
dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, ((buffer.byteLength + 3) >> 2) << 2)) | ||
} catch(error) { | ||
// if it is write at the end of the ArrayBuffer, we may need to retry with the exact remaining bytes | ||
dataView = buffer.dataView || (buffer.dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.buffer.byteLength - buffer.byteOffset)) | ||
} | ||
let highInt = dataView.getInt32(position) << 4 | ||
@@ -219,4 +235,3 @@ let size = end - position | ||
value = BigInt(value); | ||
let exponent = highInt >> 20; | ||
// TODO: negatives? | ||
let exponent = highInt >> 20 & 0x7ff; | ||
let next_byte = buffer[position - 1] & 0xf; | ||
@@ -223,0 +238,0 @@ value += BigInt(next_byte) << BigInt(exponent - 1079); |
{ | ||
"name": "ordered-binary", | ||
"author": "Kris Zyp", | ||
"version": "1.5.0", | ||
"version": "1.5.1", | ||
"description": "Conversion of JavaScript primitives to and from Buffer with binary order matching natural primitive order", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -50,2 +50,3 @@ import { assert } from 'chai' | ||
test('bigint equivalence', () => { | ||
assert.strictEqual(fromBufferKey(toBufferKey(-35913040084491349n)), -35913040084491349n) | ||
assert.strictEqual(fromBufferKey(toBufferKey(6135421331404949076605986n)), 6135421331404949076605986n) | ||
@@ -64,2 +65,3 @@ assert.strictEqual(fromBufferKey(toBufferKey(0xfffffffffffffffffffffn)), 0xfffffffffffffffffffffn) | ||
assert.strictEqual(BigInt(fromBufferKey(toBufferKey(num))), num) | ||
assert.strictEqual(BigInt(fromBufferKey(toBufferKey(-num))), -num) | ||
} | ||
@@ -66,0 +68,0 @@ assert.strictEqual(fromBufferKey(toBufferKey(-352n)), -352) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57712
1034