Re: Taking -1 to integer powers <INT_MIN or >INT_MAX yields NaN

  • From: Philipp Kutin <philipp.kutin@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 18 Nov 2013 23:57:05 +0100

Oops ... And here's the Lua script as attachment.

--Philipp
local io = require("io")
local math = require("math")

local ipairs = ipairs
local pairs = pairs

local ffi

if (jit) then
    ffi = require("ffi")
    ffi.cdef[[double pow(double x, double y);]]
end

local exps = { -2^31-1, -2^31, -2^31+1,
               2^31-2, 2^31-1, 2^31,
}

local funcs = {
    pow_c = ffi and function(x, y) return ffi.C.pow(x, y) end or nil,
    pow_lm = function(x, y) return math.pow(x, y) end,
    pow_lop = function(x, y) return x^y end,
}

for fname, f in pairs(funcs) do
    io.write(fname, ": ")
    for _, exp in ipairs(exps) do
        io.write(f(-1, exp), " ")
    end
    io.write("\n")
end

Other related posts: