utils: Add a comment to the scaling functions to explain why the rounding is correct

This commit is contained in:
Sebastian Dröge 2009-09-09 18:38:29 +02:00
parent 6a872b0b14
commit c4f76d5d22

View file

@ -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) { \