Removed `isnegative` subroutine from stdlib.
[vvhitespace] / stdlib / math.pvvs
CommitLineData
3625ff3a
AT
1#ifndef VVS_STDLIB_MATH
2#define VVS_STDLIB_MATH
3
2612f47f 4@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a
AT
5@ Name:
6@ random (10000)
2612f47f 7@ Description:
b15f1da5
AT
8@ Returns a kinda-random number.
9@ Before using for the first time, seed heap[0] with a value.
2612f47f
AT
10@ Call Stack:
11@ empty
12@ Return Stack:
13@ random number <-- TOS
14@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
15NSSVTSSSSN | Mark: 10000 (random)
b15f1da5
AT
16
17@ Generate the next seed value
18SSSSN | PUSH 0 (ptr)
19TTT | LOAD
20SSSTSSSSSTTTSSSTTSSTSSTTTSSTTSTTSTN | PUSH 1103515245
21TSSN | MULTIPLY
22SSSTTSSSSSSTTTSSTN | PUSH 12345
23TSSS | ADD
24
25@ Store the next seed value but keep a copy on the stack.
26SNS | DUP
27SSSSN | PUSH 0 (ptr)
28SNT | SWAP
29TTS | STORE
30
31@ Calculate the random number and return.
32SSSTSSSSSSSSSSSSSSSSN | PUSH 65536
33TSTS | DIVIDE
34SSSTSSSSSSSSSSSSSSSN | PUSH 32768
35TSTT | MODULO
2612f47f
AT
36NTN | RTS
37
3625ff3a 38@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bb21580a
AT
39@ Name:
40@ abs (10001)
3625ff3a 41@ Description:
bb21580a 42@ Returns the absolute value of its argument
3625ff3a
AT
43@ Call Stack:
44@ signed number <-- TOS
45@ Return Stack:
46@ abs(signed number) <-- TOS
47@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
48NSSVTSSSTN | Mark: 10001 (absolute value)
49SNS | DUP
50NTTSSSTSSSTSSSSSSSSN | BMI > 00010001 00000000
51NSNSSSTSSSTSSSSSSSTN | JMP > 00010001 00000001
52NSSVSSSTSSSTSSSSSSSSN | Mark: 00010001 00000000
53SSTTN | PUSH -1
54TSSN | MULTIPLY
55NSSVSSSTSSSTSSSSSSSTN | Mark: 00010001 00000001
56NTN | RTS
57
58#endif