Message359710
_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). |
|
Date |
User |
Action |
Args |
2020-01-10 08:23:22 | vstinner | set | recipients:
+ vstinner, benjamin.peterson, graingert |
2020-01-10 08:23:22 | vstinner | set | messageid: <1578644602.6.0.199118556483.issue39277@roundup.psfhosted.org> |
2020-01-10 08:23:22 | vstinner | link | issue39277 messages |
2020-01-10 08:23:22 | vstinner | create | |
|