- Joined
- Jan 21, 2006
- Messages
- 2,552
Does anybody need this? It's a simple algorithm that will return the greatest common factor between two integers. If you need to find the GCD of real values then you can multiply them by a power of 10 and then divide the answer by the same power of 10.
Where should something like this be posted? The JASS section? It's but a single function.
By the way, one application of this (with conversion from reals) is timer systems. You could effectively accommodate several periodic intervals by simply finding the GCD of all of them. For example, let's say you've got 3 timers with different intervals:
0.075
0.03
0.15
This GCD algorithm will yield (after conversions to/from real values): 0.015
It's kind of nifty. I use it a lot in University.
** Maybe I should make it a text-macro instead for all those speed freaks.
JASS:
function gcd takes integer value1, integer value2 returns integer
local integer r
if (value1 < value2) then
set r = value1
set value1 = value2
set value2 = r
endif
loop
set r = value1 - value2 * (value1/value2)
exitwhen (r == 0)
set value1 = value2
set value2 = r
endloop
return value2
endfunction
Where should something like this be posted? The JASS section? It's but a single function.
By the way, one application of this (with conversion from reals) is timer systems. You could effectively accommodate several periodic intervals by simply finding the GCD of all of them. For example, let's say you've got 3 timers with different intervals:
0.075
0.03
0.15
This GCD algorithm will yield (after conversions to/from real values): 0.015
It's kind of nifty. I use it a lot in University.
** Maybe I should make it a text-macro instead for all those speed freaks.