diff options
Diffstat (limited to 'src/commonlib/bsd/gcd.c')
-rw-r--r-- | src/commonlib/bsd/gcd.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/commonlib/bsd/gcd.c b/src/commonlib/bsd/gcd.c new file mode 100644 index 0000000000..92b601e8d0 --- /dev/null +++ b/src/commonlib/bsd/gcd.c @@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: BSD-3-Clause */ + +#include <commonlib/bsd/gcd.h> +#include <commonlib/bsd/helpers.h> +#include <stdint.h> + +uint32_t gcd32(uint32_t a, uint32_t b) +{ + uint32_t c; + + if (a == 0 || b == 0) + return MAX(a, b); + + c = a % b; + + while (c > 0) { + a = b; + b = c; + c = a % b; + } + + return b; +} |