00001 #ifndef SINT
00002 #define SINT
00003 #include <int_s.h>
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 namespace SPUC {
00027
00031 template <long Bits=32> class sint : public int_s
00032 {
00033 public:
00034 sint<Bits>() {
00035 bits=Bits-1;
00036 mask = -1 << bits;
00037 }
00038 sint<Bits>(long y) {
00039 q = y;
00040 bits=Bits-1;
00041 mask = -1 << bits;
00042 }
00043 inline sint<Bits> operator =(const int_s& y) {
00044 q = y.q;
00045 sign = (y.q & (1 << bits));
00046 if ( ((mask&q)!=mask) || ((mask&q)!=0) ) {
00047 q &= ~mask;
00048 if (sign) q |= mask;
00049 }
00050 return *this;
00051 }
00052 inline sint<Bits> operator =(const long& y) {
00053 if (bitpos) {
00054 if (y) q |= MASK_BIT(bitpos);
00055 else q &= ~MASK_BIT(bitpos);
00056 bitpos = 0;
00057 } else {
00058 q = y;
00059 sign = (y & (1 << bits));
00060 if ( ((mask&q)!=mask) || ((mask&q)!=0) ) {
00061 q &= ~mask;
00062 if (sign) q |= mask;
00063 }
00064 }
00065 return *this;
00066 }
00068 inline sint<Bits> operator ()(long i) {
00069 bitpos = i;
00070 return *this;
00071 }
00072
00073 };
00074
00075 }
00076 #endif