diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/pulsecore/core-util.c | 24 | ||||
-rw-r--r-- | src/pulsecore/core-util.h | 3 |
2 files changed, 27 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); +} diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index fd6ee896..d9fad11e 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -206,4 +206,7 @@ static inline pa_bool_t pa_in_valgrind(void) { } #endif +unsigned pa_gcd(unsigned a, unsigned b); +void pa_reduce(unsigned *num, unsigned *den); + #endif |