From 19ba6b14e20738c82ad539b2a4b0690e7880e3cb Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Wed, 1 Feb 2017 08:18:28 +0100 Subject: sync with Context as of 2017-02-01 --- lualibs-number.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lualibs-number.lua') 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 -- cgit v1.2.3