From c4f76d5d2213db923257d6b9dd939b409e7133b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Wed, 9 Sep 2009 18:38:29 +0200 Subject: [PATCH] utils: Add a comment to the scaling functions to explain why the rounding is correct --- gst/gstutils.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gst/gstutils.c b/gst/gstutils.c index 1eb456909a..a68c6187f9 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -352,6 +352,16 @@ gst_util_div128_64 (GstUInt64 c1, GstUInt64 c0, guint64 denom) } #endif /* defined (__GNUC__) */ +/* This always gives the correct result because: + * a) val <= G_MAXUINT64-1 + * b) (c0,c1) <= G_MAXUINT64 * (G_MAXUINT64-1) + * or + * (c0,c1) == G_MAXUINT64 * G_MAXUINT64 and denom < G_MAXUINT64 + * (note: num==denom case is handled by short path) + * This means that (c0,c1) either has enough space for val + * or that the overall result will overflow anyway. + */ + /* add correction with carry */ #define CORRECT(c0,c1,val) \ if (val) { \