Yidi Lin | 909c317 | 2023-10-31 14:57:04 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
2 | |||||
3 | #include <commonlib/bsd/gcd.h> | ||||
4 | #include <commonlib/bsd/helpers.h> | ||||
5 | #include <stdint.h> | ||||
6 | |||||
7 | uint32_t gcd32(uint32_t a, uint32_t b) | ||||
8 | { | ||||
9 | uint32_t c; | ||||
10 | |||||
11 | if (a == 0 || b == 0) | ||||
12 | return MAX(a, b); | ||||
13 | |||||
14 | c = a % b; | ||||
15 | |||||
16 | while (c > 0) { | ||||
17 | a = b; | ||||
18 | b = c; | ||||
19 | c = a % b; | ||||
20 | } | ||||
21 | |||||
22 | return b; | ||||
23 | } |