1-- @docclass math
2
3local U8 = 2^8
4local U16 = 2^16
5local U32 = 2^32
6local U64 = 2^64
7
8function math.round(num, idp)
9 local mult = 10^(idp or 0)
10 if num >= 0 then
11 return math.floor(num * mult + 0.5) / mult
12 else
13 return math.ceil(num * mult - 0.5) / mult
14 end
15end
16
17function math.isu8(num)
18 return math.isinteger(num) and num >= 0 and num < U8
19end
20
21function math.isu16(num)
22 return math.isinteger(num) and num >= U8 and num < U16
23end
24
25function math.isu32(num)
26 return math.isinteger(num) and num >= U16 and num < U32
27end
28
29function math.isu64(num)
30 return math.isinteger(num) and num >= U32 and num < U64
31end
32
33function math.isinteger(num)
34 return ((type(num) == 'number') and (num == math.floor(num)))
35end
36