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:
parent
a54cacb508
commit
75fc9ee84b
1 changed files with 13 additions and 3 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue