Skip to content

Commit a75afb8

Browse files
ShadowNinjakwolekr
authored andcommittedJul 8, 2013
Move math.hypot() to misc_helpers.lua and fix zero-division error
1 parent 9dcd219 commit a75afb8

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed
 

‎builtin/misc.lua

-10
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,3 @@ function minetest.formspec_escape(str)
106106
return str
107107
end
108108

109-
function math.hypot(x, y)
110-
local t
111-
x = math.abs(x)
112-
y = math.abs(y)
113-
t = math.min(x, y)
114-
x = math.max(x, y)
115-
t = t / x
116-
return x * math.sqrt(1 + t * t)
117-
end
118-

‎builtin/misc_helpers.lua

+10
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,14 @@ function minetest.pos_to_string(pos)
9191
return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")"
9292
end
9393

94+
function math.hypot(x, y)
95+
local t
96+
x = math.abs(x)
97+
y = math.abs(y)
98+
t = math.min(x, y)
99+
x = math.max(x, y)
100+
if x == 0 then return 0 end
101+
t = t / x
102+
return x * math.sqrt(1 + t * t)
103+
end
94104

0 commit comments

Comments
 (0)
Please sign in to comment.