summaryrefslogtreecommitdiff
path: root/lualibs-number.lua
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2017-02-04 13:50:34 +0100
committerGitHub <noreply@github.com>2017-02-04 13:50:34 +0100
commit42f669beab39df38d2f4955b651541272126a04e (patch)
treef68d918629725f9306698bf0641910d1f714714b /lualibs-number.lua
parent144f6d16fd79bd0496b3ae379b69227e0d9bbfa9 (diff)
parent1b2f8c0355210dbfd34b10ed4ff7f0c90fda062d (diff)
downloadlualibs-master.tar.gz
Merge pull request #31 from phi-gamma/masterHEADmaster
v2.5
Diffstat (limited to 'lualibs-number.lua')
-rw-r--r--lualibs-number.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/lualibs-number.lua b/lualibs-number.lua
index 001ca31..c6f1e33 100644
--- a/lualibs-number.lua
+++ b/lualibs-number.lua
@@ -13,6 +13,7 @@ local tostring, tonumber = tostring, tonumber
local format, floor, match, rep = string.format, math.floor, string.match, string.rep
local concat, insert = table.concat, table.insert
local lpegmatch = lpeg.match
+local floor = math.floor
number = number or { }
local number = number
@@ -205,3 +206,25 @@ end
function number.bits(n)
return { bits(n,1) }
end
+
+function number.bytetodecimal(b)
+ local d = floor(b * 100 / 255 + 0.5)
+ if d > 100 then
+ return 100
+ elseif d < -100 then
+ return -100
+ else
+ return d
+ end
+end
+
+function number.decimaltobyte(d)
+ local b = floor(d * 255 / 100 + 0.5)
+ if b > 255 then
+ return 255
+ elseif b < -255 then
+ return -255
+ else
+ return b
+ end
+end