2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass math
|
|
|
|
|
2013-01-16 20:57:05 +01:00
|
|
|
local U8 = 2^8
|
|
|
|
local U16 = 2^16
|
|
|
|
local U32 = 2^32
|
|
|
|
local U64 = 2^64
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
function math.round(num, idp)
|
|
|
|
local mult = 10^(idp or 0)
|
|
|
|
if num >= 0 then
|
2013-01-16 20:57:05 +01:00
|
|
|
return math.floor(num * mult + 0.5) / mult
|
2012-06-26 00:13:30 +02:00
|
|
|
else
|
2013-01-16 20:57:05 +01:00
|
|
|
return math.ceil(num * mult - 0.5) / mult
|
2012-06-26 00:13:30 +02:00
|
|
|
end
|
|
|
|
end
|
2013-01-16 20:57:05 +01:00
|
|
|
|
|
|
|
function math.isu8(num)
|
|
|
|
return math.isinteger(num) and num >= 0 and num < U8
|
|
|
|
end
|
|
|
|
|
|
|
|
function math.isu16(num)
|
|
|
|
return math.isinteger(num) and num >= U8 and num < U16
|
|
|
|
end
|
|
|
|
|
|
|
|
function math.isu32(num)
|
|
|
|
return math.isinteger(num) and num >= U16 and num < U32
|
|
|
|
end
|
|
|
|
|
|
|
|
function math.isu64(num)
|
|
|
|
return math.isinteger(num) and num >= U32 and num < U64
|
|
|
|
end
|
|
|
|
|
|
|
|
function math.isinteger(num)
|
|
|
|
return ((type(num) == 'number') and (num == math.floor(num)))
|
|
|
|
end
|