mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
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
This commit is contained in:
parent
e94ff65809
commit
8fef95c5c2
2 changed files with 34 additions and 1 deletions
|
@ -1,3 +1,10 @@
|
|||
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:
|
||||
|
|
Loading…
Reference in a new issue