-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_functions.py
More file actions
65 lines (41 loc) · 1013 Bytes
/
basic_functions.py
File metadata and controls
65 lines (41 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
BASIC "runtime" functions.
More or less following the semantics found at:
https://hackage.haskell.org/package/vintage-basic-1.0/src/doc/Vintage_BASIC_Users_Guide.html
"""
import random
import math
def ASC(val):
return ord(val)
def COS(val):
return math.cos(val)
def CHR(val):
return chr(val) # Can print bell (7) or backspace (10), or TAB (11)
def INT(val):
return int(val)
def LEFT(string: str, num: int):
return string[:num]
def LEN(val):
return len(val)
_prev_rand_val = 0
def RND(val):
global _prev_rand_val
if val > 0:
_prev_rand_val = random.random()
return _prev_rand_val
elif val < 0:
random.seed(val)
else: # == 0
return _prev_rand_val
def SIN(val):
return math.sin(val)
def SGN(val):
if val == 0:
return 0
elif val > 0:
return 1
return -1
def TAB(num: int): # TODO: Actually, this implementation is not right
return ' ' * num
def TAN(val):
return math.tan(val)