/* 15-347 Spring '98 */ /* Skeleton Code for testing arithmetic expressions using restricted syntax */ /* Assumes two's complement integer representations */ /* The Makefile contains a declaration of the word size. You may need to adjust it for your machine. Be careful to use the constants 0L and 1L instead of 0 and 1 so that your code will work on machines for which ints and long ints have different sizes */ /* Minimum two's complement integer */ long int TMin(void) { return 1L << WORD_SIZE-1L; } /* -1L */ long int minus_one(void) { return ~0L; } /* Maximum two's complement integer */ long int TMax(void) { return ~(1L << WORD_SIZE-1L); } /* x == 0L ? */ long int isZero(long int x) { return !x; } /* x < 0L ? */ long int isNegative(long int x) { return (x >> WORD_SIZE-1L) & 1L; } /* x > 0L ? */ long int isPositive(long int x) { return !(!x | x >> WORD_SIZE-1L); } /* -x */ long int negate(long int x) { return ~x+1L; } /* |x| (except returns TMin for Tmin) */ long int absval(long int x) { return (x ^ x>>WORD_SIZE-1L) + ~(x>>WORD_SIZE-1L) + 1L; } /* x == y */ long int isEqual(long int x, long int y) { return !(x + ~y + 1L); } long int isGreater(long int x, long int y) { return !(x>>WORD_SIZE-1L) & y>>WORD_SIZE-1L | !(x>>WORD_SIZE-1L ^ y>>WORD_SIZE-1L) & (y+~x+1L)>>WORD_SIZE-1L; }