From 3560691c0aecd89dc7f7d91ed8c4f1eaa9715eaf Mon Sep 17 00:00:00 2001 From: Vincent Robinson Date: Thu, 1 Apr 2021 15:18:58 -0700 Subject: Add `math.round` and fix `vector.round` (#10803) --- builtin/common/misc_helpers.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'builtin/common/misc_helpers.lua') diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 0f3897f47..d5f25f2fe 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -244,6 +244,15 @@ function math.factorial(x) return v end + +function math.round(x) + if x >= 0 then + return math.floor(x + 0.5) + end + return math.ceil(x - 0.5) +end + + function core.formspec_escape(text) if text ~= nil then text = string.gsub(text,"\\","\\\\") -- cgit v1.2.3