X-Git-Url: http://git.subgeniuskitty.com/vvhitespace/.git/blobdiff_plain/e0d5136cb09e6ac4680796af169a611ff6c97996..7359501c4b44efadc76eef5570008dd52f6767fc:/stdlib/math.pvvs diff --git a/stdlib/math.pvvs b/stdlib/math.pvvs index 7bd73e5..3876c6e 100644 --- a/stdlib/math.pvvs +++ b/stdlib/math.pvvs @@ -46,6 +46,17 @@ NTN | RTS @ abs(signed number) <-- TOS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ NSSVTSSSTN | Mark: 10001 (absolute value) + +@ Catch -(2^63) as a special case since its absolute value will overflow +@ a twos-complement 64-bit word. Return zero as though the absolute value +@ overflowed to the bottom of the non-negative integers rather than +@ overflowing back to the most negative integer. +SNS | DUP +SSTTSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSN | -(2^63) +TSST | SUBTRACT +NTSSSSTSSSTSSSSSSTSN | BRZ > 00010001 00000010 + +@ Handle all the other numbers. SNS | DUP NTTSSSTSSSTSSSSSSSSN | BMI > 00010001 00000000 NSNSSSTSSSTSSSSSSSTN | JMP > 00010001 00000001 @@ -55,22 +66,10 @@ 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 +@ Special case: Push 0 and return. +NSSVSSSTSSSTSSSSSSTSN | Mark: 00010001 00000010 +SNN | DROP SSSSN | PUSH 0 NTN | RTS -NSSVSTSSSSSTSSSSSSSSN | Mark: 01000001 00000000 -SSSTN | PUSH 1 -NTN | RTS #endif