Message262653
time.localtime(float("NaN")) raises a ValueError on x86_64 using the few compilers I have tested it with. (this makes sense)
>>> time.localtime(float("NaN"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: (75, 'Value too large for defined data type')
On an arm and arm64 system, it does not and treats NaN as 0. (nonsense!)
>>> time.localtime(float("NaN"))
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)
The root of this problem appears to be the (potentially questionable? I'll ask a C compiler person...) code in Python/pytime.c's (3.x) Modules/timemodule.c's (2.7) double to time_t conversion function.
I'm not sure what it does is supposed to be well defined behavior with NaN...
The easy fix is to add:
#include <math.h>
and
add || isnan(x) || isinf(x) to the check that raises a ValueError in
https://hg.python.org/cpython/file/4c903ceeb4d1/Python/pytime.c#l149 (3.x)
https://hg.python.org/cpython/file/2.7/Modules/timemodule.c#l102 (2.7)
Along with a relevant assertRaises(ValueError) unittest for NaN, inf and -inf in test_time.py. |
|
Date |
User |
Action |
Args |
2016-03-30 07:17:23 | gregory.p.smith | set | recipients:
+ gregory.p.smith |
2016-03-30 07:17:23 | gregory.p.smith | set | messageid: <1459322243.53.0.921219428076.issue26669@psf.upfronthosting.co.za> |
2016-03-30 07:17:23 | gregory.p.smith | link | issue26669 messages |
2016-03-30 07:17:22 | gregory.p.smith | create | |
|