Skip to content

Commit

Permalink
Move math.hypot() to misc_helpers.lua and fix zero-division error
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowNinja authored and kwolekr committed Jul 8, 2013
1 parent 9dcd219 commit a75afb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 0 additions & 10 deletions builtin/misc.lua
Expand Up @@ -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

10 changes: 10 additions & 0 deletions builtin/misc_helpers.lua
Expand Up @@ -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

0 comments on commit a75afb8

Please sign in to comment.