Skip to content

Commit a223e7e

Browse files
committed
wip
1 parent 8f536ae commit a223e7e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

index.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,30 @@ module.exports = function toBuffer(data, encoding) {
7878
var offset = j * elemSize;
7979
var value = data[j]; // Get the actual element value
8080

81-
// Write the value in little-endian format based on size
81+
// Write the value in little-endian format based on size and type
8282
if (elemSize === 1) {
8383
// 8-bit values have no endianness
8484
outputView.setUint8(offset, value);
8585
} else if (elemSize === 2) {
8686
// 16-bit values - write as little-endian
8787
outputView.setUint16(offset, value, true);
8888
} else if (elemSize === 4) {
89-
// 32-bit values - write as little-endian
90-
outputView.setUint32(offset, value, true);
89+
// 32-bit values - check if it's a float
90+
if (typeof value === 'number' && !Number.isInteger(value)) {
91+
outputView.setFloat32(offset, value, true);
92+
} else {
93+
outputView.setUint32(offset, value, true);
94+
}
9195
} else if (elemSize === 8) {
92-
// 64-bit values - write as little-endian
93-
outputView.setBigUint64(offset, value, true);
96+
// 64-bit values - check if it's a BigInt or float
97+
if (typeof value === 'bigint') {
98+
outputView.setBigUint64(offset, value, true);
99+
} else if (typeof value === 'number') {
100+
outputView.setFloat64(offset, value, true);
101+
} else {
102+
// Fallback - shouldn't happen but just in case
103+
outputView.setFloat64(offset, Number(value), true);
104+
}
94105
}
95106
}
96107
}

0 commit comments

Comments
 (0)