[gstreamer-bugs] [Bug 342943] New: algorithm to avoid overflows when multiplying fractions
GStreamer (bugzilla.gnome.org)
bugzilla-daemon at bugzilla.gnome.org
Thu May 25 11:25:33 PDT 2006
Do not reply to this via email (we are currently unable to handle email
responses and they get discarded). You can add comments to this bug at
http://bugzilla.gnome.org/show_bug.cgi?id=342943
GStreamer | gstreamer (core) | Ver: HEAD CVS
Summary: algorithm to avoid overflows when multiplying fractions
Product: GStreamer
Version: HEAD CVS
Platform: Other
OS/Version: All
Status: UNCONFIRMED
Severity: enhancement
Priority: Normal
Component: gstreamer (core)
AssignedTo: gstreamer-bugs at lists.sourceforge.net
ReportedBy: torri at iecn.u-nancy.fr
QAContact: gstreamer-bugs at lists.sourceforge.net
GNOME version: Unspecified
GNOME milestone: Unspecified
as requested by Thomas, i post here a simple algorithm that try to avoid some
overflows when multiplying fractions. It's only maths, no computer science.
To compute a fraction from a numerator num and a denominator den, first compute
the gcd d of num and den with the Euclid algorithm. Then the resulting
"simplified" fraction is (num / d, den / d).
if r1=(num1, den1) and r2=(num2, den2) are 2 fractions. I suppose that they are
already simplified.
a) compute the rational r3=(num1, den2) using the simplification above
b) compute the rational r4=(num2, den1) using the simplification above
c) the result of r1 * r2 is the rational r5=(r3.num * r4.num, r3.den * r4.den)
and it's no need to simplify this fraction. It's already simplified.
another way to say that :
a) d1 = gcd(num1, den2)
b) d2 = gcd(num2, den1)
c) r1 * r2 is the fraction ( (num1 / d1) * (num2 / d2), (den1 / d2) * (den2 /
d1) )
they is another algo if the fraction is multiplied by an integer only.
I don't know if multiplications of fractions are handled this way in gstreamer.
Nevertheless, I hope this helps
Vincent
--
Configure bugmail: http://bugzilla.gnome.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.
More information about the Gstreamer-bugs
mailing list