This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients benjamin.peterson, graingert, vstinner
Date 2020-01-10.08:23:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1578644602.6.0.199118556483.issue39277@roundup.psfhosted.org>
In-reply-to
Content
_PyTime_FromDouble() checks if!(_Py_DoubleInIntegralTypeRange(_PyTime_t, d)) with the macro:

#define _Py_InIntegralTypeRange(type, v) (_Py_IntegralTypeMin(type) <= v && v <= _Py_IntegralTypeMax(type))

and _Py_IntegralTypeMax(type)=2**63-1.

"v <= _Py_IntegralTypeMax(type)" compares a C double to a C int64_t: the compiler casts the C int64_t to a C double.

The problem is that 2**63-1 casted to a C double rounds using ROUND_HALF_EVEN rounding mode which gives a number *greater* than 2**63-1: we get 2**63.

To implement "v <= max", we have to round max towards zero (ROUND_DOWN), not round it using ROUND_HALF_EVEN.

I didn't find a way to control the rounding mode of casting C int64_t to C double, but we can round it *afterwards* using nextafter(max, 0.0) (ROUND_DOWN).
History
Date User Action Args
2020-01-10 08:23:22vstinnersetrecipients: + vstinner, benjamin.peterson, graingert
2020-01-10 08:23:22vstinnersetmessageid: <1578644602.6.0.199118556483.issue39277@roundup.psfhosted.org>
2020-01-10 08:23:22vstinnerlinkissue39277 messages
2020-01-10 08:23:22vstinnercreate