From: Sebastien Bourdeauducq Date: Thu, 12 Dec 2013 16:36:50 +0000 (+0100) Subject: utils/misc: add gcd_multiple function to compute GCD or any number of integers X-Git-Tag: 24jan2021_ls180~2099^2~391 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=adffec35f6cd0311f81c46250a0d65387a276b06;p=litex.git utils/misc: add gcd_multiple function to compute GCD or any number of integers --- diff --git a/migen/util/misc.py b/migen/util/misc.py index 6846b4a5..799c58e8 100644 --- 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:]))