Fix (float)"nan" and (vector)"<nan,-nan..." on Windows.

We were letting Python typecast, and that causes the wrong result on Windows. Return the correct result explicitly when "nan" is found in the string.

Also, small reformatting of an else if -> elif.
This commit is contained in:
Sei Lisa 2017-02-12 06:05:57 +01:00
parent 44dd088154
commit 9a1421aeeb

View file

@ -59,10 +59,10 @@ from base64 import b64encode, b64decode
# The lookahead (?!i) is essential for parsing them that way without extra code.
# Note that '|' in REs is order-sensitive.
float_re = re.compile(ur'^\s*[+-]?(?:0(x)(?:[0-9a-f]+(?:\.[0-9a-f]*)?|\.[0-9a-f]+)(?:p[+-]?[0-9]+)?'
ur'|(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:e[+-]?[0-9]+)?|inf|nan)',
ur'|(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:e[+-]?[0-9]+)?|inf|(nan))',
re.I)
vfloat_re = re.compile(ur'^\s*[+-]?(?:0(x)(?:[0-9a-f]+(?:\.[0-9a-f]*)?|\.[0-9a-f]+)(?:p[+-]?[0-9]+)?'
ur'|(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:e[+-]?[0-9]+)?|infinity|inf(?!i)|nan)',
ur'|(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:e[+-]?[0-9]+)?|infinity|inf(?!i)|(nan))',
re.I)
int_re = re.compile(ur'^0(x)[0-9a-f]+|^\s*[+-]?[0-9]+', re.I)
@ -421,8 +421,7 @@ def InternalTypecast(val, out, InList, f32):
return 0.0
if match.group(1):
ret = F32(float.fromhex(match.group(0)), f32)
else:
if match.group(0).lower() == '-nan':
elif match.group(2):
# (float)"-nan" produces NaN instead of Indet, even though
# (vector)"<-nan,0,0>" produces <Indet, 0., 0.>. Go figure.
ret = NaN
@ -457,6 +456,8 @@ def InternalTypecast(val, out, InList, f32):
return Z
if match.group(1):
ret.append(F32(float.fromhex(match.group(0)), f32))
elif match.group(2):
ret.append(Indet if match.group(0)[0] == '-' else NaN)
else:
ret.append(F32(float(match.group(0)), f32))
if len(ret) < dim: