Fix bug in float shrinking code.

This commit is contained in:
Sei Lisa 2014-07-31 18:47:40 +02:00
parent a303ef2066
commit be9145e3c3

View file

@ -82,15 +82,16 @@ class outscript(object):
# Repeat the operation with the incremented number # Repeat the operation with the incremented number
while news[-1] != '.' and lslfuncs.F32(float(neg+news[:-1]+exp)) == value: while news[-1] != '.' and lslfuncs.F32(float(neg+news[:-1]+exp)) == value:
news = news[:-1] news = news[:-1]
if len(neg+news) < len(s) and lslfuncs.F32(float(neg+news[:-1]+exp)) == value: if len(neg+news) < len(s) and lslfuncs.F32(float(neg+news+exp)) == value:
# Success! But we try even harder. # Success! But we try even harder. We may have converted
# 9.9999e3 into 10.e3; that needs to be turned into 1.e4.
if exp != '': if exp != '':
if news[2:3] == '.': # we converted 9.9... into 10. if news[2:3] == '.': # we converted 9.9... into 10.
newexp = 'e' + str(int(exp[1:])+1) # increase exponent newexp = 'e' + str(int(exp[1:])+1) # increase exponent
news2 = news[0] + '.' + news[1] + news[3:] # move dot to the left news2 = news[0] + '.' + news[1] + news[3:] # move dot to the left
while news2[-1] == '0': # remove trailing zeros while news2[-1] == '0': # remove trailing zeros
news2 = news2[:-1] news2 = news2[:-1]
if len(neg+news2) < len(s) and lslfuncs.F32(float(neg+news2[:-1]+newexp)) == value: if len(neg+news2) < len(s) and lslfuncs.F32(float(neg+news2+newexp)) == value:
news = news2 news = news2
exp = newexp exp = newexp
s = neg+news s = neg+news