4 # note: python 3 returns int type from math.floor(), I don't really
5 # like this, but I rely on it below to avoid needing explicit int()
8 # should check for illegal quantity error here?
9 # real applesoft seems to allow up to 63999, but it's not really
10 # clear under what circumstances it should be treated as unsigned
11 assert isinstance(value, float)
12 return ((math.floor(value) + 0x8000) & 0xffff) - 0x8000
14 def str_dollar(context, value):
15 assert isinstance(value, float)
25 exponent = math.floor(math.log10(value))
32 f'?OVERFLOW ERROR IN {context.line_number():d}'
34 value *= 10. ** (8 - exponent)
36 int_value = int(round(value))
37 assert int_value >= 100000000
38 if int_value >= 1000000000:
43 f'?OVERFLOW ERROR IN {context.line_number():d}'
45 int_value = int(round(value))
46 assert int_value >= 100000000 and int_value < 1000000000
48 value = str(int_value)
49 if exponent >= -2 and exponent < 9:
52 value = '0' * -exponent + value
54 value = value[:exponent] + '.' + value[exponent:]
57 value = value[:1] + '.' + value[1:]
62 exponent = 'E' + exponent_sign + ('0' + str(exponent))[-2:]
65 while value[i] == '0':
69 return sign + value[:i] + exponent
94 '(\ *[+-])?(((\ *[0-9]*)*)\ *\.((\ *[0-9])*)|((\ *[0-9])+))(\ *E(\ *[+-])?\ *((\ *[0-9])+))?'
97 match = re_val.match(value)
100 sign = (match.group(1) or '').replace(' ', '')
101 integer = (match.group(3) or match.group(7) or '').replace(' ', '')
102 fraction = (match.group(5) or '').replace(' ', '')
104 if match.group(9) is not None:
105 exp_sign = (match.group(10) or '').replace(' ', '')
106 exp = int(match.group(11).replace(' ', ''))
109 result = int(integer + fraction) * 10. ** (exp - len(fraction))
112 return len(match.group(0)), result