Created
July 9, 2015 15:08
-
-
Save GinjaNinja32/5747d5b497f74c725982 to your computer and use it in GitHub Desktop.
cheap_pythag() vs sqrt()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/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