lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 1/1/2012 4:51 PM, Mike Pall wrote:
Eliot Eikenberry wrote:
I've been spending the weekend trying to gain a deeper understanding
of noise functions and trying to see what interesting things I can
get out of them.  After getting through Perlin/Simplex noise and
diving into Worley(Cell) Noise, I discovered what appears to be a
bug with the LuaJIT BitOp library when dealing with exceedingly
large numbers.  Namely, i'm experiencing this bug with the
BitOp.band function.
Not a bug. http://bitop.luajit.org/semantics.html#undefined

noise1d = function(x, r)
     local n = x * r
     n = bit.bxor(bit.lshift(n, 13), n)
Now assume: n = 2^31-1

     n = n * (n * n * 15731 + 789221) + 1376312589
n = 155792277846347238669208840085402
Which is way bigger than 2^51.

     n = (1.0 - bit.band(n, 2147483647) / 1073741824.0)
Which makes bit.band(n, 2147483647) an undefined operation.

And undefined really means 'undefined'. The compiler could do
anything: output random numbers, play towers of hanoi ...

--Mike

Ah, thanks. Been forever since I've looked at the documentation for the jit and it's companion libraries, guess i need to give it another read over.