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
This commit is contained in:
Amaury Pouly 2010-02-02 20:49:35 +00:00
parent a54cacb508
commit 75fc9ee84b

View file

@ -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;