10 #ifndef OVERFLOWSAFE_TYPE_HPP
11 #define OVERFLOWSAFE_TYPE_HPP
23 template <
class T, T T_MAX, T T_MIN>
48 (this->m_value < 0) == (other.
m_value < 0)) {
49 this->m_value = (this->m_value < 0) ? T_MIN : T_MAX ;
78 if (factor != 0 && (T_MAX /
abs(factor)) <
abs(this->m_value)) {
79 this->m_value = ((this->m_value < 0) == (factor < 0)) ? T_MAX : T_MIN ;
81 this->m_value *= factor ;
94 inline OverflowSafeInt& operator /= (
const int64 divisor) { this->m_value /= divisor;
return *
this; }
100 inline OverflowSafeInt& operator %= (
const int divisor) { this->m_value %= divisor;
return *
this; }
104 inline OverflowSafeInt& operator <<= (
const int shift) { this->m_value <<= shift;
return *
this; }
106 inline OverflowSafeInt& operator >>= (
const int shift) { this->m_value >>= shift;
return *
this; }
111 inline bool operator != (
const OverflowSafeInt& other)
const {
return !(*
this == other); }
114 inline bool operator < (
const OverflowSafeInt& other)
const {
return !(*
this >= other); }
115 inline bool operator <= (
const OverflowSafeInt& other)
const {
return !(*
this > other); }
118 inline bool operator == (
const int other)
const {
return this->m_value == other; }
119 inline bool operator != (
const int other)
const {
return !(*
this == other); }
120 inline bool operator > (
const int other)
const {
return this->m_value > other; }
121 inline bool operator >= (
const int other)
const {
return this->m_value >= other; }
122 inline bool operator < (
const int other)
const {
return !(*
this >= other); }
123 inline bool operator <= (
const int other)
const {
return !(*
this > other); }
125 inline operator int64 ()
const {
return this->
m_value; }