From 75fc9ee84b73287bdca627f414bc91c964b238d8 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Tue, 2 Feb 2010 20:49:35 +0000 Subject: FS#8967: Fix autoscore computation overflow when the playtime is huge. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24471 a1c6a512-1295-4272-9138-f99709370657 --- apps/tagcache.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'apps/tagcache.c') diff --git a/apps/tagcache.c b/apps/tagcache.c index 79c96ff186..9ffb6f86fe 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -772,9 +772,19 @@ static long check_virtual_tags(int tag, const struct index_entry *idx) } else { - data = 100 * idx->tag_seek[tag_playtime] - / idx->tag_seek[tag_length] - / idx->tag_seek[tag_playcount]; + /* A straight calculus gives: + autoscore = 100 * playtime / length / playcout (1) + Now, consider the euclidian division of playtime by length: + playtime = alpha * length + beta + With: + 0 <= beta < length + Now, (1) becomes: + autoscore = 100 * (alpha / playcout + beta / length / playcount) + Both terms should be small enough to avoid any overflow + */ + data = 100 * (idx->tag_seek[tag_playtime] / idx->tag_seek[tag_length]) + + (100 * (idx->tag_seek[tag_playtime] % idx->tag_seek[tag_length])) / idx->tag_seek[tag_length]; + data /= idx->tag_seek[tag_playcount]; } break; -- cgit v1.2.3