_hx_bit_clamp.lua 714 B

1234567891011121314151617181920212223242526
  1. if _hx_bit_raw then
  2. _hx_bit_clamp = function(v)
  3. if v <= 2147483647 and v >= -2147483648 then
  4. if v > 0 then return _G.math.floor(v)
  5. else return _G.math.ceil(v)
  6. end
  7. end
  8. if v > 2251798999999999 then v = v*2 end;
  9. if (v ~= v or math.abs(v) == _G.math.huge) then return nil end
  10. return _hx_bit_raw.band(v, 2147483647 ) - math.abs(_hx_bit_raw.band(v, 2147483648))
  11. end
  12. else
  13. _hx_bit_clamp = function(v)
  14. if v < -2147483648 then
  15. return -2147483648
  16. elseif v > 2147483647 then
  17. return 2147483647
  18. elseif v > 0 then
  19. return _G.math.floor(v)
  20. else
  21. return _G.math.ceil(v)
  22. end
  23. end
  24. end;