diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-09-18 12:21:14 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-09-18 12:21:14 (GMT) |
commit | ec26f83f2ea13d7f15c461ac49d46dfcdf49b8ec (patch) | |
tree | 4e6c2a4ca830582b09e61df574c0935982ef058e /Python | |
parent | 02d6a25beaa3922f487e984a852c2ef2127d0a7f (diff) | |
download | cpython-ec26f83f2ea13d7f15c461ac49d46dfcdf49b8ec.zip cpython-ec26f83f2ea13d7f15c461ac49d46dfcdf49b8ec.tar.gz cpython-ec26f83f2ea13d7f15c461ac49d46dfcdf49b8ec.tar.bz2 |
Issue #25155: Fix _PyTime_Divide() rounding
_PyTime_Divide() rounding was wrong: copy code from Python default which has
now much better unit tests.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pytime.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index 85e1ca8..5a5cdd9 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -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 |