Lines Matching defs:Modulo

22 // Modulo class is used for intentionally wrapping variables such as
29 // 1) Modulo checks type sizes before performing operations to ensure
31 // 2) Modulo returns Modulo types from arithmetic operations, thereby
32 // avoiding unintentional use in a non-modular computation. A Modulo
33 // type is converted to its base non-Modulo type through the value() function.
34 // 3) Modulo separates out overflowable types from non-overflowable types.
36 // Modulo types do not participate in sanitization.
37 // 4) Modulo comparisons are based on signed differences to account for wrap;
85 template <typename T> class Modulo {
92 Modulo() { } // intentionally uninitialized data
93 Modulo(const T &value) { mValue = value; }
102 Modulo<T> operator +=(const Modulo<S> &other) {
110 Modulo<T> operator -=(const Modulo<S> &other) {
117 // Modulo base type sizes, but we only allow equal sizes to avoid confusion.
120 const Modulo<T> operator +(const Modulo<S> &other) const {
122 return Modulo<T>(mValue + other.unsignedValue());
127 const Modulo<T> operator -(const Modulo<S> &other) const {
129 return Modulo<T>(mValue - other.unsignedValue());
139 bool operator >(const Modulo<S> &other) const {
146 bool operator >=(const Modulo<S> &other) const {
153 bool operator ==(const Modulo<S> &other) const {
160 bool operator <=(const Modulo<S> &other) const {
167 bool operator <(const Modulo<S> &other) const {
173 // modular operations with a non-Modulo type allowed with wrapping
177 Modulo<T> operator +=(const S &other) {
184 Modulo<T> operator -=(const S &other) {
189 // modular operations with a non-Modulo type allowed with wrapping,
195 // Note: a Modulo type may be promoted by using "differences" off of
199 const Modulo<T> operator +(const S &other) const {
201 return Modulo<T>(mValue + unsignedT(other));
206 const Modulo<T> operator -(const S &other) const {
208 return Modulo<T>(mValue - unsignedT(other));