From 60f257279bfab509e9fcc696e2767c3fdafe6efd Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sun, 15 May 2016 19:55:45 +0200 Subject: [PATCH] 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. --- lslopt/lslbasefuncs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lslopt/lslbasefuncs.py b/lslopt/lslbasefuncs.py index eb6a4d8..caf7b57 100644 --- a/lslopt/lslbasefuncs.py +++ b/lslopt/lslbasefuncs.py @@ -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)