gstutils: add a 64 bit version of GCD calculation
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Wed, 30 Nov 2011 17:58:07 +0000 (17:58 +0000)
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>
Tue, 24 Jan 2012 12:11:44 +0000 (12:11 +0000)
https://bugzilla.gnome.org/show_bug.cgi?id=665294

gst/gstutils.c
gst/gstutils.h

index 52c0a86..363dee0 100644 (file)
@@ -3522,6 +3522,32 @@ gst_util_greatest_common_divisor (gint a, gint b)
 }
 
 /**
+ * gst_util_greatest_common_divisor_int64:
+ * @a: First value as #gint64
+ * @b: Second value as #gint64
+ *
+ * Calculates the greatest common divisor of @a
+ * and @b.
+ *
+ * Returns: Greatest common divisor of @a and @b
+ *
+ * Since: 0.11.0
+ */
+gint64
+gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b)
+{
+  while (b != 0) {
+    gint64 temp = a;
+
+    a = b;
+    b = temp % b;
+  }
+
+  return ABS (a);
+}
+
+
+/**
  * gst_util_fraction_to_double:
  * @src_n: Fraction numerator as #gint
  * @src_d: Fraction denominator #gint
index 7bdc350..c3f8ec6 100644 (file)
@@ -957,6 +957,7 @@ gpointer      gst_util_array_binary_search      (gpointer array, guint num_eleme
 
 /* fraction operations */
 gint          gst_util_greatest_common_divisor  (gint a, gint b);
+gint64        gst_util_greatest_common_divisor_int64 (gint64 a, gint64 b);
 
 void          gst_util_fraction_to_double       (gint src_n, gint src_d, gdouble *dest);
 void          gst_util_double_to_fraction       (gdouble src, gint *dest_n, gint *dest_d);