Implement rounded_div

Round-to-nearest integral based division, optimized for unsigned integral.
Used in sceNpTrophyGetGameProgress.
Do not allow signed values for aligned_div(), align().
This commit is contained in:
Eladash 2019-12-16 21:56:14 +02:00 committed by kd-11
parent e30173a835
commit db4041e079
6 changed files with 31 additions and 16 deletions

View file

@ -929,8 +929,9 @@ error_code sceNpTrophyGetGameProgress(u32 context, u32 handle, vm::ptr<s32> perc
const u32 trp_count = ctxt->tropusr->GetTrophiesCount();
verify(HERE), trp_count > 0 && trp_count <= 128;
*percentage = static_cast<s32>(std::lround((unlocked * 100.) / trp_count));
// Round result to nearest
*percentage = rounded_div(unlocked * 100, trp_count);
return CELL_OK;
}