Author tim.peters
Recipients aconrad, belopolsky, larry, mark.dickinson, r.david.murray, tbarbugli, tim.peters, trcarden, vivanov, vstinner
Date 2015-08-29.01:40:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> >>> x = float.fromhex('0x1.38f312b1b36bdp-1')
> >>> x
> 0.6112295
> >>> round(x, 6)
> 0.611229
> >>> timedelta(0, x).microseconds
> 611230
> but I no longer remember whether we concluded that
> timedelta got it wrong or round or both or neither. :-)

Here you go:

>>> import decimal
>>> decimal.Decimal(x)

That's the exact value you're actually using.  What's "correct" depends on what's intended.

round(x, 6) actually rounds to

>>> decimal.Decimal(round(x, 6))

and that's fine.  timedelta's result does not match what using infinite precision would deliver, but I couldn't care much less ;-)

The real lesson to take from all this, when you design your own killer language, is that using a binary floating point type for timestamps comes with many costs and surprises.
Date User Action Args
2015-08-29 01:40:11tim.peterssetrecipients: + tim.peters, mark.dickinson, belopolsky, vstinner, larry, r.david.murray, aconrad, vivanov, tbarbugli, trcarden
2015-08-29 01:40:11tim.peterssetmessageid: <>
2015-08-29 01:40:11tim.peterslinkissue23517 messages
2015-08-29 01:40:10tim.peterscreate