Commit 8fef95c5 authored by Jan Schmidt's avatar Jan Schmidt Committed by Edward Hervey

gst/__init__.py: Make gst.Fraction simplify like the C counterpart

Original commit message from CVS:
Patch by: Jan Schmidt <thaytan at mad dot scientist dot com>
* gst/__init__.py:
Make gst.Fraction simplify like the C counterpart
Fixes #532809
parent e94ff658
2008-05-14 Edward Hervey <edward.hervey@collabora.co.uk>
Patch by: Jan Schmidt <thaytan at mad dot scientist dot com>
* gst/__init__.py:
Make gst.Fraction simplify like the C counterpart
Fixes #532809
2008-05-14 Edward Hervey <edward.hervey@collabora.co.uk>
* gst/gstcaps.override:
......
......@@ -77,10 +77,37 @@ class FractionRange(Value):
class Fraction(Value):
def __init__(self, num, denom=1):
def __gcd(a,b):
while b != 0:
tmp = a
a = b
b = tmp % b
return abs(a)
def __simplify():
num = self.num
denom = self.denom
if num < 0:
num = -num
denom = -denom
# Compute greatest common divisor
gcd = __gcd(num,denom)
if gcd != 0:
num /= gcd
denom /= gcd
self.num = num
self.denom = denom
Value.__init__(self, 'fraction')
self.num = num
self.denom = denom
__simplify()
def __repr__(self):
return '<gst.Fraction %d/%d>' % (self.num, self.denom)
......@@ -118,7 +145,6 @@ class Fraction(Value):
def __float__(self):
return float(self.num) / float(self.denom)
import sys
dlsave = sys.getdlopenflags()
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment