From: ShadowNinja Date: Sun, 7 Jul 2013 16:02:11 +0000 (-0400) Subject: Move math.hypot() to misc_helpers.lua and fix zero-division error X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=a75afb85ca6338da847172bbed3cc776d3aced20;p=zefram%2Fminetest%2Fminetest_engine.git Move math.hypot() to misc_helpers.lua and fix zero-division error --- diff --git a/builtin/misc.lua b/builtin/misc.lua index 4be03c38..f4e7dbca 100644 --- a/builtin/misc.lua +++ b/builtin/misc.lua @@ -106,13 +106,3 @@ function minetest.formspec_escape(str) return str end -function math.hypot(x, y) - local t - x = math.abs(x) - y = math.abs(y) - t = math.min(x, y) - x = math.max(x, y) - t = t / x - return x * math.sqrt(1 + t * t) -end - diff --git a/builtin/misc_helpers.lua b/builtin/misc_helpers.lua index 743a9cfd..0439415b 100644 --- a/builtin/misc_helpers.lua +++ b/builtin/misc_helpers.lua @@ -91,4 +91,14 @@ function minetest.pos_to_string(pos) return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")" end +function math.hypot(x, y) + local t + x = math.abs(x) + y = math.abs(y) + t = math.min(x, y) + x = math.max(x, y) + if x == 0 then return 0 end + t = t / x + return x * math.sqrt(1 + t * t) +end