compat: float reads return the canonical NaN for NaN payloads (checked through the bits: no aliased LuaJIT object values); host: raise LuaJIT trace / mcode limits (opt-out FORMATS_NO_JIT_TUNE)
This commit is contained in:
1 parent
66c373bbec
commit
94f9a68d50
2 files changed
+28
No files matched your search
@@ -267,12 +267,19 @@ do
|
||||
if o < 0 or o + 4 > b.n then oob() end
|
||||
return cast(i32p, b.p + o)[0]
|
||||
end
|
||||
-- NaNs are checked through their bits before the float is loaded: a NaN with an arbitrary payload, handed back by
|
||||
-- the FFI, can alias LuaJIT's NaN-tagged object values (read as a table / userdata). Return the canonical NaN.
|
||||
local NAN = 0 / 0
|
||||
function Buf.readf32(b, o)
|
||||
if o < 0 or o + 4 > b.n then oob() end
|
||||
local bits = cast(u32p, b.p + o)[0]
|
||||
if bits % 0x80000000 > 0x7f800000 then return NAN end
|
||||
return cast(f32p, b.p + o)[0]
|
||||
end
|
||||
function Buf.readf64(b, o)
|
||||
if o < 0 or o + 8 > b.n then oob() end
|
||||
local hi = cast(u32p, b.p + o + 4)[0] % 0x80000000 -- little-endian: sign / exponent / top mantissa bits
|
||||
if hi >= 0x7ff00000 and (hi > 0x7ff00000 or cast(u32p, b.p + o)[0] ~= 0) then return NAN end
|
||||
return cast(f64p, b.p + o)[0]
|
||||
end
|
||||
-- integer writes wrap like Luau (300 -> 44, -1 -> 255); the double -> int conversion goes through int32 for
|
||||
|
||||
Reference in new issue
Block a user