diff options
Diffstat (limited to 'src/pulsecore/core-util.c')
-rw-r--r-- | src/pulsecore/core-util.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index dde34d7b..6f315666 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2487,3 +2487,27 @@ pa_bool_t pa_in_valgrind(void) { return b > 1; } #endif + +unsigned pa_gcd(unsigned a, unsigned b) { + + while (b > 0) { + unsigned t = b; + b = a % b; + a = t; + } + + return a; +} + +void pa_reduce(unsigned *num, unsigned *den) { + + unsigned gcd = pa_gcd(*num, *den); + + if (gcd <= 0) + return; + + *num /= gcd; + *den /= gcd; + + pa_assert(pa_gcd(*num, *den) == 1); +} |