Message156371
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? |
|
Date |
User |
Action |
Args |
2012-03-20 00:14:55 | vstinner | set | recipients:
+ vstinner, rhettinger, facundobatista, mark.dickinson, belopolsky, skrah, cool-RR |
2012-03-20 00:14:54 | vstinner | set | messageid: <1332202494.81.0.460679304607.issue14262@psf.upfronthosting.co.za> |
2012-03-20 00:14:54 | vstinner | link | issue14262 messages |
2012-03-20 00:14:54 | vstinner | create | |
|