31
Technical support / Re:Square root
« on: December 16, 2005, 03:29:52 AM »
And if you want rounding to nearest, instead of rounding down, it changes in detail but not really all that much:
square=12345678 ' The number we want to find the square-root of.
sqroot=0 ' The resultant square-root.
index = &8000 ' The bit mask indexing.
check = 0 ' The lookahead sqroot - Added for faster execution.
sqrt_loop:
check = sqroot + index
index = index >> 1
if (check * check - check) < square then sqroot = check
if index<>0 then sqrt_loop
Evan
square=12345678 ' The number we want to find the square-root of.
sqroot=0 ' The resultant square-root.
index = &8000 ' The bit mask indexing.
check = 0 ' The lookahead sqroot - Added for faster execution.
sqrt_loop:
check = sqroot + index
index = index >> 1
if (check * check - check) < square then sqroot = check
if index<>0 then sqrt_loop
Evan