mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
Issue #8644: Improve accuracy of timedelta.total_seconds, by doing intermediate
computations with integer arithmetic instead of floating point. td.total_seconds() now agrees with td / timedelta(seconds = 1). Thanks Alexander Belopolsky for the patch.
This commit is contained in:
parent
161b024b6d
commit
0381e3f16a
4 changed files with 33 additions and 4 deletions
|
@ -264,6 +264,11 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
|
|||
for total_seconds in [123456.789012, -123456.789012, 0.123456, 0, 1e6]:
|
||||
td = timedelta(seconds=total_seconds)
|
||||
self.assertEqual(td.total_seconds(), total_seconds)
|
||||
# Issue8644: Test that td.total_seconds() has the same
|
||||
# accuracy as td / timedelta(seconds=1).
|
||||
for ms in [-1, -2, -123]:
|
||||
td = timedelta(microseconds=ms)
|
||||
self.assertEqual(td.total_seconds(), td / timedelta(seconds=1))
|
||||
|
||||
def test_carries(self):
|
||||
t1 = timedelta(days=100,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue