Use math.copysign to distinguish indeterminates

We were using a very dubious method to distinguish an indeterminate from a NaN, via struct.unpack. Turns out that math.copysign gets the job done and seems more robust.
This commit is contained in:
Sei Lisa 2016-05-15 19:55:45 +02:00
parent b06ac33b5f
commit 60f257279b

View file

@ -1024,8 +1024,7 @@ def llList2CSV(lst):
for elem in lst:
# This always uses LSO rules for float to string.
if type(elem) == float:
from struct import pack
if math.isnan(elem) and pack('>f', elem)[0:1] == b'\xff':
if math.isnan(elem) and math.copysign(1.0, elem) < 0:
ret.append(u'-nan')
else:
ret.append(u'%.6f' % elem)