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:50:40 +0100

Just noticed this when I wanted to find out about the C library's
behavior in these corner cases. I attached a small test script. It
takes -1 to powers of INT_MIN+{-1,0,1} and INT_MAX+{-1,0,1} and gives
the following output for me on x86_86:

$ luajit pow32.lua
pow_lop: -nan 1 -1 1 -1 -nan  -- Lua ^ operator
pow_c: -1 1 -1 1 -1 1  -- ffi.C.pow
pow_lm: -nan 1 -1 1 -1 -nan  -- Lua math.pow

$ lua pow32.lua
pow_lm: -1 1 -1 1 -1 1
pow_lop: -1 1 -1 1 -1 1

Arguably, exponentiating by such large numbers is pretty cornerly and
-1 is about the only interesting LHS... I'm wondering if there are use
cases for that.

--Philipp

Other related posts: