#ifndef _UNSIGNED_ARITH #define _UNSIGNED_ARITH $system int $remainder(int x, int y); /* This file defines certain arithmetic functions on unsigned integers * in terms of ordinary integer arithmetic operations. * Each function consumes the integer arguments for the operation, and * an additional parameter named bound. The bound should be one * greater than the maximum unsigned value of the particular type. * Hence these functions can be used for all unsigned integer types * by invoking with the appropriate bound: unsigned char, unsigned * short, unsigned int, unsigned long, unsigned long long. * * There is no need for division or modulus operations, since the * usual integer operations can be used for these. (As they * cannot overflow or underflow.) * * For an expression x, the expression x++ can be translated as * (x=y) return x-y; else return x-y+bound; } /* Computes product of two unsigned values. * Preconditions: 0= 0) { if (x < bound) return x; else return $remainder(x,bound); } else { if (-x <= bound) return bound + x; else return bound - $remainder(-x,bound); } } /* Computes -x for an unsigned integer x. * Preconditions: 0