corsix
Joined 12 years ago
Karma
234
Submissions
54
Member since
Sep 23
Joined 12 years ago
The related FRSQRTE instruction is much more conventional, operating on 32-bit floats, again giving approximate inverse square root.
local ffi = require"ffi"
local function collect_lots()
for i = 1, 20 do collectgarbage() end
end
local function f(s)
local blob = ffi.new"int[2]"
local interior = blob + 1
interior[0] = 13 -- should become the return value
s:gsub(".", collect_lots)
return interior[0] -- kept alive by blob?
end
for i = 1, 60 do
local str = ("x"):rep(i - 59)
assert(f(str) == 13) -- can fail!!
end