! longint.inf - test harness for longint.h (long integer support for Inform) ! ! Mainly by Chris Hall - c@pobox.co.uk. ! Signed integer support by Francis Irving - francis@pobox.co.uk. ! Please email us with any errors, omissions or if you've ! found this code useful. ! ! (If you need to edit this file, note that indentations are 4 spaces ! and tabs are not used.) ! ! This source code is distributed free, but remains ! Copyright 1997-1998 Chris Hall and Francis Irving. Release 1. Include "longint"; [Main; Arithmetic(); ArrayOfLongs(); ]; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! This section shows how to make an array (ServerUse) ! of long integer variables. Constant MAX_SERVERS = 10; ! Allow four times the number of servers - 4 bytes per server ! Make sure you store this calculation as a separate constant. If ! you include the calculation directly in the Array definition below, then ! it doesn't work due to an Inform 6.14 bug. Constant SERVER_SPACE = MAX_SERVERS * 4; ! Byte array to store longs for servers numbered 0 to (MAX_SERVERS - 1) Array ServerUse -> SERVER_SPACE; Array one -> 4; [ArrayOfLongs n c; print MAX_SERVERS, " max^"; for (n=0: n < MAX_SERVERS: ++n) { c = (ServerUse + (n*4)); LongSet((ServerUse + (n*4)), 0, 0, 0, 0); } LongSet(one, 0, 0, 0, 1); for (c=0: c < 50: ++c) { n = random(MAX_SERVERS) - 1; LongAdd(ServerUse + (n*4), ServerUse + (n*4), one); print "Server ", n, " now at ", (longunsign) (ServerUse + (n*4)), "^"; } ]; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! This section makes three long integer variables, and tests the ! arithmetic functions using them. ! This is how you declare each of your long variables. They can ! be signed or unsigned. Both types are declared the same - ! you just use different functions to manipulate them. Array x->4; Array y->4; Array z->4; [Arithmetic; LongSet(x,$4a,$65,$75,$c0); LongSet(y,$3a,$de,$68,$b1); LongAdd(z,x,y); print (longunsign)x,"+",(longunsign)y,"=",(longunsign)z,"^"; LongSet(x,$7d,$c2,$29,$3f); LongSet(y,$07,$5b,$cd,$15); LongSub(z,x,y); print (longsign)x,"-",(longsign)y,"=",(longsign)z,"^"; LongSub(z,y,x); print (longsign)y,"-",(longsign)x,"=",(longsign)z,"^"; print "^"; ! You can use LongSet like this, to fill in small numbers. LongSet(x,0,0,0,0); LongSet(y,0,0,0,1); LongSub(z,x,y); print (longsign)x,"-",(longsign)y,"=",(longsign)z,"^"; print "^"; LongSet(x,$00,$00,$30,$39); LongSet(y,$00,$01,$81,$cd); LongMul(z,x,y); print (longsign)x,"*",(longsign)y,"=",(longsign)z,"^"; LongSignNegAssign(x, x); LongMul(z,x,y); print (longsign)x,"*",(longsign)y,"=",(longsign)z,"^"; LongSignNegAssign(y, y); LongMul(z,x,y); print (longsign)x,"*",(longsign)y,"=",(longsign)z,"^"; LongSignNegAssign(x, x); LongMul(z,x,y); print (longsign)x,"*",(longsign)y,"=",(longsign)z,"^"; print "^"; LongSet(x,$00,$00,$ff,$ff); LongSet(y,$00,$00,$ff,$ff); LongMul(z,x,y); print (longunsign)x,"*",(longunsign)y,"=",(longunsign)z,"^"; print "^"; LongSet(x,$49,$96,$02,$d2); LongSet(y,$00,$00,$00,$07); LongSignDiv(z,x,y); print (longsign)x,"/",(longsign)y,"=",(longsign)z,"^"; LongSignMod(z,x,y); print (longsign)x,"%",(longsign)y,"=",(longsign)z,"^"; LongSignNegAssign(x, x); LongSignDiv(z,x,y); print (longsign)x,"/",(longsign)y,"=",(longsign)z,"^"; LongSignMod(z,x,y); print (longsign)x,"%",(longsign)y,"=",(longsign)z,"^"; LongSignNegAssign(y, y); LongSignDiv(z,x,y); print (longsign)x,"/",(longsign)y,"=",(longsign)z,"^"; LongSignMod(z,x,y); print (longsign)x,"%",(longsign)y,"=",(longsign)z,"^"; LongSignNegAssign(x, x); LongSignDiv(z,x,y); print (longsign)x,"/",(longsign)y,"=",(longsign)z,"^"; LongSignMod(z,x,y); print (longsign)x,"%",(longsign)y,"=",(longsign)z,"^"; print "^"; LongSet(x, 0, 0, 0, 13); LongSet(y, 0, 0, 0, 1); LongSignDiv(z, x, y); print (longsign)x,"/",(longsign)y,"=",(longsign)z,"^"; LongSignDiv(z, y, x); print (longsign)y,"/",(longsign)x,"=",(longsign)z,"^"; print "^"; LongSet(x,$4a,$65,$75,$c0); LongSignNegAssign(y, x); print "-", (longsign)x, "=", (longsign)y, "^"; LongSet(x,0,0,0,5); LongSet(y,0,0,0,6); print (longsign)x,"<",(longsign)y,"=", LongSignLT(x, y) ,"^"; print (longsign)y,"<",(longsign)x,"=", LongSignLT(y, x) ,"^"; LongSignNegAssign(y, y); print (longsign)x,"<",(longsign)y,"=", LongSignLT(x, y) ,"^"; print (longsign)y,"<",(longsign)x,"=", LongSignLT(y, x) ,"^"; LongSignNegAssign(x, x); print (longsign)x,"<",(longsign)y,"=", LongSignLT(x, y) ,"^"; print (longsign)y,"<",(longsign)x,"=", LongSignLT(y, x) ,"^"; LongSignNegAssign(y, y); print (longsign)x,"<",(longsign)y,"=", LongSignLT(x, y) ,"^"; print (longsign)y,"<",(longsign)x,"=", LongSignLT(y, x) ,"^"; ];