STINNER Victor <[email protected]> added the comment:
My patch looses precision for big numbers. It's better to convert Decimal to a
number of microseconds.
Wrong:
>>> value=86400*365.25*999999+1e-6; print(datetime.timedelta(seconds=value))
365249634 days, 18:00:00
>>> value=decimal.Decimal(86400*365.25*999999)+decimal.Decimal('1e-6');
>>> print(datetime.timedelta(seconds=float(value)))
365249634 days, 18:00:00
Correct:
>>> value=decimal.Decimal(86400*365.25*999999)+decimal.Decimal('1e-6');
>>> print(datetime.timedelta(microseconds=int(value*decimal.Decimal(10**6))))
365249634 days, 18:00:00.000001
I'm not completly conviced by the need of supporting Decimal in timedelta
constructor. Why do you use Decimal if the result should be a timedelta? Why
not using timedelta directly?
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue14262>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com