summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_time.py16
-rw-r--r--Python/pytime.c11
2 files changed, 16 insertions, 11 deletions
diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py
index 6bcd212..de0cbc4 100644
--- a/Lib/test/test_time.py
+++ b/Lib/test/test_time.py
@@ -946,14 +946,14 @@ class TestPyTime_t(unittest.TestCase):
# nanoseconds
(1, 0, FLOOR),
(1, 1, CEILING),
- (-1, 0, FLOOR),
- (-1, -1, CEILING),
+ (-1, -1, FLOOR),
+ (-1, 0, CEILING),
# seconds + nanoseconds
(1234 * MS_TO_NS + 1, 1234, FLOOR),
(1234 * MS_TO_NS + 1, 1235, CEILING),
- (-1234 * MS_TO_NS - 1, -1234, FLOOR),
- (-1234 * MS_TO_NS - 1, -1235, CEILING),
+ (-1234 * MS_TO_NS - 1, -1235, FLOOR),
+ (-1234 * MS_TO_NS - 1, -1234, CEILING),
):
with self.subTest(nanoseconds=ns, milliseconds=ms, round=rnd):
self.assertEqual(PyTime_AsMilliseconds(ns, rnd), ms)
@@ -983,14 +983,14 @@ class TestPyTime_t(unittest.TestCase):
# nanoseconds
(1, 0, FLOOR),
(1, 1, CEILING),
- (-1, 0, FLOOR),
- (-1, -1, CEILING),
+ (-1, -1, FLOOR),
+ (-1, 0, CEILING),
# seconds + nanoseconds
(1234 * US_TO_NS + 1, 1234, FLOOR),
(1234 * US_TO_NS + 1, 1235, CEILING),
- (-1234 * US_TO_NS - 1, -1234, FLOOR),
- (-1234 * US_TO_NS - 1, -1235, CEILING),
+ (-1234 * US_TO_NS - 1, -1235, FLOOR),
+ (-1234 * US_TO_NS - 1, -1234, CEILING),
):
with self.subTest(nanoseconds=ns, milliseconds=ms, round=rnd):
self.assertEqual(PyTime_AsMicroseconds(ns, rnd), ms)
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