projects
/
litex.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
c13fe1b
)
utils/misc: add gcd_multiple function to compute GCD or any number of integers
author
Sebastien Bourdeauducq
<sebastien@milkymist.org>
Thu, 12 Dec 2013 16:36:50 +0000
(17:36 +0100)
committer
Sebastien Bourdeauducq
<sebastien@milkymist.org>
Thu, 12 Dec 2013 16:36:50 +0000
(17:36 +0100)
migen/util/misc.py
patch
|
blob
|
history
diff --git
a/migen/util/misc.py
b/migen/util/misc.py
index 6846b4a5bab47a1de2be33c4f653386bdee53d3d..799c58e8fe3a9bbccd7a3234432fb08f3c48240f 100644
(file)
--- a/
migen/util/misc.py
+++ b/
migen/util/misc.py
@@
-1,3
+1,4
@@
+from fractions import gcd
import collections
def flat_iteration(l):
@@
-26,3
+27,11
@@
def autotype(s):
except ValueError:
pass
return s
+
+def gcd_multiple(numbers):
+ l = len(numbers)
+ if l == 1:
+ return numbers[0]
+ else:
+ s = l//2
+ return gcd(gcd_multiple(numbers[:s]), gcd_multiple(numbers[s:]))