update file.write_bytes to support bytearray + bit_converter bytearray support

This commit is contained in:
MihailRis
2024-06-16 22:55:56 +03:00
parent 6bf23e5cac
commit bfdd92ca51
2 changed files with 10 additions and 7 deletions
+5 -5
View File
@@ -68,19 +68,19 @@ local function floatOrDoubleToBytes(val, opt)
if opt == 'd' then
val = mantissa
for i = 1, 6 do
table.insert(bytes, math.floor(val) % (2 ^ 8))
bytes[#bytes + 1] = math.floor(val) % (2 ^ 8)
val = math.floor(val / (2 ^ 8))
end
else
table.insert(bytes, math.floor(mantissa) % (2 ^ 8))
bytes[#bytes + 1] = math.floor(mantissa) % (2 ^ 8)
val = math.floor(mantissa / (2 ^ 8))
table.insert(bytes, math.floor(val) % (2 ^ 8))
bytes[#bytes + 1] = math.floor(val) % (2 ^ 8)
val = math.floor(val / (2 ^ 8))
end
table.insert(bytes, math.floor(exponent * ((opt == 'd') and 16 or 128) + val) % (2 ^ 8))
bytes[#bytes + 1] = math.floor(exponent * ((opt == 'd') and 16 or 128) + val) % (2 ^ 8)
val = math.floor((exponent * ((opt == 'd') and 16 or 128) + val) / (2 ^ 8))
table.insert(bytes, math.floor(sign * 128 + val) % (2 ^ 8))
bytes[#bytes + 1] = math.floor(sign * 128 + val) % (2 ^ 8)
val = math.floor((sign * 128 + val) / (2 ^ 8))
if not endianness then