| 61 | */ |
| 62 | template<uint value_size> |
| 63 | class Int : public UInt<value_size> |
| 64 | { |
| 65 | public: |
| 66 | |
| 67 | /*! |
| 68 | this method sets the max value which this class can hold |
| 69 | (all bits will be one besides the last one) |
| 70 | */ |
| 71 | void SetMax() |
| 72 | { |
| 73 | UInt<value_size>::SetMax(); |
| 74 | UInt<value_size>::table[value_size-1] = ~ TTMATH_UINT_HIGHEST_BIT; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | /*! |
| 79 | this method sets the min value which this class can hold |
| 80 | (all bits will be zero besides the last one which is one) |
| 81 | */ |
| 82 | void SetMin() |
| 83 | { |
| 84 | UInt<value_size>::SetZero(); |
| 85 | UInt<value_size>::table[value_size-1] = TTMATH_UINT_HIGHEST_BIT; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /*! |
| 90 | this method sets -1 as the value |
| 91 | (-1 is equal the max value in an unsigned type) |
| 92 | */ |
| 93 | void SetSignOne() |
| 94 | { |
| 95 | UInt<value_size>::SetMax(); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | /*! |
| 100 | we change the sign of the value |
| 101 | |
| 102 | if it isn't possible to change the sign this method returns 1 |
| 103 | else return 0 and changing the sign |
| 104 | */ |
| 105 | uint ChangeSign() |
| 106 | { |
| 107 | /* |
| 108 | if the value is equal that one which has been returned from SetMin |
| 109 | (only the highest bit is set) that means we can't change sign |
| 110 | because the value is too big (bigger about one) |
| 111 | |
| 112 | e.g. when value_size = 1 and value is -2147483648 we can't change it to the |
| 113 | 2147483648 because the max value which can be held is 2147483647 |
| 114 | |
| 115 | we don't change the value and we're using this fact somewhere in some methods |
| 116 | (if we look on our value without the sign we get the correct value |
| 117 | eg. -2147483648 in Int<1> will be 2147483648 on the UInt<1> type) |
| 118 | */ |
| 119 | if( UInt<value_size>::IsOnlyTheHighestBitSet() ) |
| 120 | return 1; |
nothing calls this directly
no test coverage detected