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:
Mark Dickinson 2010-05-08 14:35:02 +00:00
parent 161b024b6d
commit 0381e3f16a
4 changed files with 33 additions and 4 deletions

View file

@ -287,7 +287,10 @@ Instance methods:
.. method:: timedelta.total_seconds()
Return the total number of seconds contained in the duration. Equivalent to
``td.microseconds / 1000000 + td.seconds + td.days * 24 * 3600``.
``td / timedelta(seconds=1)``.
Note that for very large time intervals (greater than 270 years on
most platforms) this method will lose microsecond accuracy.
.. versionadded:: 3.2