Mathematics Mathematical functions.
§1. Unsigned integer comparison. Comparison of integers is normally signed, that is, treating the word as
a twos-complement signed number, so that $FFFF is less than 0, for
instance. If we want to construe words as being unsigned integers, or as
addresses, we need to compare them with the following routine, which returns
1 if \INWEBMATH(x>y\INWEBMATH), 0 if \INWEBMATH(x=y\INWEBMATH) and \INWEBMATH(-1\INWEBMATH) if \INWEBMATH(x<y\INWEBMATH).
[ UnsignedCompare x y u v; if (x == y) return 0; if (x < 0 && y >= 0) return 1; if (x >= 0 && y < 0) return -1; u = x&~WORD_HIGHBIT; v= y&~WORD_HIGHBIT; if (u > v) return 1; return -1; ];
§2. Fully random word. This should be our best try at a single word consisting of 16 uniformly
random bits. random($100)-1 is a fully random byte.
[ FullyRandomWord; return (random($100)-1)*$100 + (random($100)-1); ];
[ VM_SquareRoot num; return 0; ]; [ VM_CubeRoot num; return 0; ];
[ REAL_NUMBER_TY_Say real; print real; ]; [ REAL_NUMBER_TY_Compare r1 r2; return UnsignedCompare(r1, r2); ];