Message108601
>> The timedelta(seconds=0.6112295) example is handled correctly
> No, it's not! It's being rounded *up* where it should be
> being rounded *down*.
Let me try to reformulate the issue. When use is entering 0.6112295, she means 0.6112295, not 0x1.38f312b1b36bdp-1 or 0.61122949999999998116351207499974407255649566650390625 which are exact values of the underlying binary representation of 0.6112295. Modern Python is able to round 0.6112295 to 6 decimal places correctly:
>>> round(0.6112295, 6)
0.611229
and timedelta should do the same, but it does not:
>>> timedelta(seconds=0.6112295)
datetime.timedelta(0, 0, 611230)
With respect to accumulation, I believe the invariant that we want to have should be
timedelta(x=a, y=b, ...) == timedelta(x=a) + timedelta(y=b)
while the alternative (using higher precision addition with rounding at the end) may be more accurate in some cases, the above looks least surprising. |
|
Date |
User |
Action |
Args |
2010-06-25 14:41:28 | belopolsky | set | recipients:
+ belopolsky, tim.peters, mcherm, rhettinger, mark.dickinson, vstinner, stutzbach |
2010-06-25 14:41:28 | belopolsky | set | messageid: <1277476888.53.0.239622209471.issue8860@psf.upfronthosting.co.za> |
2010-06-25 14:41:27 | belopolsky | link | issue8860 messages |
2010-06-25 14:41:26 | belopolsky | create | |
|