Skip to content

Instantly share code, notes, and snippets.

@GinjaNinja32
Created July 9, 2015 15:08
Show Gist options
  • Save GinjaNinja32/5747d5b497f74c725982 to your computer and use it in GitHub Desktop.
Save GinjaNinja32/5747d5b497f74c725982 to your computer and use it in GitHub Desktop.
cheap_pythag() vs sqrt()
/world
loop_checks = 0
//A very crude linear approximatiaon of pythagoras theorem.
/proc/cheap_pythag(var/dx, var/dy)
dx = abs(dx); dy = abs(dy);
if(dx>=dy) return dx + (0.5*dy) //The longest side add half the shortest side approximates the hypotenuse
else return dy + (0.5*dx)
/proc/test_cheappythag(n)
for(var/x = -n to n)
for(var/y = -n to n)
cheap_pythag(x, y)
/proc/test_sqrt(n)
for(var/x = -n to n)
for(var/y = -n to n)
sqrt(x**2 + y**2)
/client/verb/test(n as num)
var/s
var/e
s = world.timeofday
test_cheappythag(n)
e = world.timeofday
world << "test_cheappythag([n]) in [e-s] ds"
sleep(1)
s = world.timeofday
test_sqrt(n)
e = world.timeofday
world << "test_sqrt([n]) in [e-s] ds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment