summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2010-02-02 20:49:35 +0000
committerAmaury Pouly <pamaury@rockbox.org>2010-02-02 20:49:35 +0000
commit75fc9ee84b73287bdca627f414bc91c964b238d8 (patch)
tree5761f3a0a2373c7f1c283092074ec19ad18af275 /apps
parenta54cacb508b7904d1923135a2d27e31d3f5a4b41 (diff)
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
Diffstat (limited to 'apps')
-rw-r--r--apps/tagcache.c16
1 files changed, 13 insertions, 3 deletions
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;