X-Git-Url: http://git.subgeniuskitty.com/vvhitespace/.git/blobdiff_plain/2612f47f558e9201f0aeaf7655661574066e0243..e0d5136cb09e6ac4680796af169a611ff6c97996:/stdlib/math.pvvs diff --git a/stdlib/math.pvvs b/stdlib/math.pvvs index 0df09ed..7bd73e5 100644 --- a/stdlib/math.pvvs +++ b/stdlib/math.pvvs @@ -2,20 +2,44 @@ #define VVS_STDLIB_MATH @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ random (10000) @ Description: -@ This function returns a random IEEE-vetted number per RFC 1149.5. +@ Returns a kinda-random number. +@ Before using for the first time, seed heap[0] with a value. @ Call Stack: @ empty @ Return Stack: @ random number <-- TOS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ NSSVTSSSSN | Mark: 10000 (random) -SSSTSSN | PUSH +4 + +@ Generate the next seed value +SSSSN | PUSH 0 (ptr) +TTT | LOAD +SSSTSSSSSTTTSSSTTSSTSSTTTSSTTSTTSTN | PUSH 1103515245 +TSSN | MULTIPLY +SSSTTSSSSSSTTTSSTN | PUSH 12345 +TSSS | ADD + +@ Store the next seed value but keep a copy on the stack. +SNS | DUP +SSSSN | PUSH 0 (ptr) +SNT | SWAP +TTS | STORE + +@ Calculate the random number and return. +SSSTSSSSSSSSSSSSSSSSN | PUSH 65536 +TSTS | DIVIDE +SSSTSSSSSSSSSSSSSSSN | PUSH 32768 +TSTT | MODULO NTN | RTS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ abs (10001) @ Description: -@ This function returns the absolute value of its argument +@ Returns the absolute value of its argument @ Call Stack: @ signed number <-- TOS @ Return Stack: @@ -31,4 +55,22 @@ TSSN | MULTIPLY NSSVSSSTSSSTSSSSSSSTN | Mark: 00010001 00000001 NTN | RTS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@ Name: +@ isnegative (1000001) +@ Description: +@ Returns 1 if 'number' is negative, 0 if positive. +@ Call Stack: +@ number <-- TOS +@ Return Stack: +@ 1 or 0 <-- TOS +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +NSSVTSSSSSTN | Mark: 1000001 (isnegative) +NTTSTSSSSSTSSSSSSSSN | BMI > 01000001 00000000 +SSSSN | PUSH 0 +NTN | RTS +NSSVSTSSSSSTSSSSSSSSN | Mark: 01000001 00000000 +SSSTN | PUSH 1 +NTN | RTS + #endif