diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-05-08 14:35:02 +0000 |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-05-08 14:35:02 +0000 |
commit | 15a1865f618213d4120ea07747279649e92f796d (patch) | |
tree | e43e9ab6db7af037c6cb00a950fdcb6b74b8070a /Lib/test/test_datetime.py | |
parent | 0a91331a7670b31002f9fbde588868dae7595851 (diff) | |
download | cpython-15a1865f618213d4120ea07747279649e92f796d.tar.gz |
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.
Diffstat (limited to 'Lib/test/test_datetime.py')
-rw-r--r-- | Lib/test/test_datetime.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py index a5b53fbc87..f65fbca375 100644 --- a/Lib/test/test_datetime.py +++ b/Lib/test/test_datetime.py @@ -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, |