Fix correctness

This commit is contained in:
hcz 2019-12-17 10:57:11 +08:00
parent a563ad0b21
commit dabaef2836

View File

@ -119,11 +119,11 @@ struct IntegerRoundingComputation
}
case RoundingMode::Round:
{
if (x < 0)
x -= scale;
switch (tie_breaking_mode)
{
case TieBreakingMode::Auto:
if (x < 0)
x -= scale;
x = (x + scale / 2) / scale * scale;
break;
case TieBreakingMode::Bankers:
@ -131,14 +131,10 @@ struct IntegerRoundingComputation
T quotient = (x + scale / 2) / scale;
if (quotient * scale == x + scale / 2)
// round half to even
x = (quotient & ~1) * scale;
x = ((quotient + (x < 0)) & ~1) * scale;
else
{
// round the others as usual
if (x < 0)
quotient -= 1;
x = quotient * scale;
}
break;
}
}