function luaU.from_double(W,s)local function c(s)local W=s%256 return(s-W)/256,string.char(W)end local E=0 if s<0 then E=1 s=-s end local F,n=math.frexp(s)if s==0 then F,n=0,0 elseif s==1/0 then F,n=0,2047 else F=(F*2-1)*math.ldexp(.5,53)n=n+1022 end local e,o=""s=math.floor(F)for W=1,6,1 do s,o=c(s)e=e..o end s,o=c(n*16+s)e=e..o s,o=c(E*128+s)e=e..o return e end

function luaU:from_double(x)
  local function grab_byte(v)
    local c = v % 256
    return (v - c) / 256, string.char(c)
  end
  local sign = 0
  if x < 0 then sign = 1; x = -x end
  local mantissa, exponent = math.frexp(x)
  if x == 0 then -- zero
    mantissa, exponent = 0, 0
  elseif x == 1/0 then
    mantissa, exponent = 0, 2047
  else
    mantissa = (mantissa * 2 - 1) * math.ldexp(0.5, 53)
    exponent = exponent + 1022
  end
  local v, byte = "" -- convert to bytes
  x = math.floor(mantissa)
  for i = 1,6 do
    x, byte = grab_byte(x); v = v..byte -- 47:0
  end
  x, byte = grab_byte(exponent * 16 + x); v = v..byte -- 55:48
  x, byte = grab_byte(sign * 128 + x); v = v..byte -- 63:56
  return v
end
