Issue #25155: Fix _PyTime_Divide() rounding

_PyTime_Divide() rounding was wrong: copy code from Python default which has
now much better unit tests.
This commit is contained in:
Victor Stinner 2015-09-18 14:21:14 +02:00
parent 02d6a25bea
commit ec26f83f2e
2 changed files with 16 additions and 11 deletions

View file

@ -305,17 +305,22 @@ _PyTime_AsNanosecondsObject(_PyTime_t t)
}
static _PyTime_t
_PyTime_Divide(_PyTime_t t, _PyTime_t k, _PyTime_round_t round)
_PyTime_Divide(const _PyTime_t t, const _PyTime_t k,
const _PyTime_round_t round)
{
assert(k > 1);
if (round == _PyTime_ROUND_CEILING) {
if (t >= 0)
return (t + k - 1) / k;
else
return t / k;
}
else {
if (t >= 0)
return t / k;
else
return (t - (k - 1)) / k;
}
else
return t / k;
}
_PyTime_t