[Python-checkins] CVS: python/nondist/sandbox/datetime datetime.py,1.33,1.34
Tim Peters
tim_one@users.sourceforge.net
Sun, 03 Mar 2002 18:23:28 -0800
Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory usw-pr-cvs1:/tmp/cvs-serv13979
Modified Files:
datetime.py
Log Message:
timedelta.__add__(): Improve floating-point accuracy.
Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** datetime.py 4 Mar 2002 01:42:03 -0000 1.33
--- datetime.py 4 Mar 2002 02:23:26 -0000 1.34
***************
*** 7,10 ****
--- 7,11 ----
import time as _time
+ import math as _math
MINYEAR = 1 # XXX The design doc says 0
***************
*** 335,343 ****
self.__microseconds)
if isinstance(other, float):
! ss, us = divmod(other*1e6, 1e6)
! d, ss = divmod(ss, 24*3600)
! return timedelta(self.__days + int(d),
! self.__seconds + int(ss),
! self.__microseconds + int(round(us)))
return NotImplemented
--- 336,349 ----
self.__microseconds)
if isinstance(other, float):
! sign = 1
! if other < 0:
! sign, other = -1, -other
! frac, whole = _math.modf(other)
! us = int(frac * 1e6 + 0.5)
! assert 0 <= us <= 1000000 # if 1e6, constructor will normalize
! days, seconds = divmod(whole, 24*3600)
! return timedelta(self.__days + sign * int(days),
! self.__seconds + sign * int(seconds),
! self.__microseconds + sign * us)
return NotImplemented