Re: ffi.cast: weird behaviour

  • From: Mike Pall <mike-1311@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Fri, 22 Nov 2013 04:46:31 +0100

Daurnimator wrote:
> This is what I ended up with: https://gist.github.com/daurnimator/7582543
> Hopefully I didn't overlook anything else...

Wrong mantissa condition, use of uint32_t, endianess issues,
efficiency issues.

  local cast, band = ffi.cast, bit.band
  local lohi_p = ffi.typeof("struct { int32_t "..(ffi.abi("le") and "lo, hi" or 
"hi, lo").."; } *")

  local function double_isnan(p)
    local q = cast(lohi_p, p)
    return band(q.hi, 0x7ff00000) == 0x7ff00000 and
           bit.bor(q.lo, band(q.hi, 0xfffff)) ~= 0
  end

--Mike

Other related posts: