summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/core-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-01-10 02:53:57 +0100
committerLennart Poettering <lennart@poettering.net>2009-01-10 02:53:57 +0100
commitc850aa0c5b5e856618f11021a3e2a338c625de67 (patch)
tree179bf64f144edbfecdc5e62857ec15a3e8ee9420 /src/pulsecore/core-util.c
parent98049fbf81fae18707281642f6ae5b23632bd068 (diff)
Add new pa_reduce() and pa_gcd() functions
Diffstat (limited to 'src/pulsecore/core-util.c')
-rw-r--r--src/pulsecore/core-util.c24
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);
+}