diff options
Diffstat (limited to 'Python/pytime.c')
-rw-r--r-- | Python/pytime.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Python/pytime.c b/Python/pytime.c index 7b55b10d10..f19bb3673e 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -120,9 +120,13 @@ _PyTime_Round(double x, _PyTime_round_t round) else if (round == _PyTime_ROUND_CEILING) { d = ceil(d); } - else { + else if (round == _PyTime_ROUND_FLOOR) { d = floor(d); } + else { + assert(round == _PyTime_ROUND_UP); + d = (d >= 0.0) ? ceil(d) : floor(d); + } return d; } @@ -427,7 +431,7 @@ _PyTime_Divide(const _PyTime_t t, const _PyTime_t k, return t / k; } } - else { + else if (round == _PyTime_ROUND_FLOOR){ if (t >= 0) { return t / k; } @@ -435,6 +439,15 @@ _PyTime_Divide(const _PyTime_t t, const _PyTime_t k, return (t - (k - 1)) / k; } } + else { + assert(round == _PyTime_ROUND_UP); + if (t >= 0) { + return (t + k - 1) / k; + } + else { + return (t - (k - 1)) / k; + } + } } _PyTime_t |