Select Git revision
-
Martin Mareš authoredMartin Mareš authored
rings.h 573 B
#ifndef __RINGS_H__
#define __RINGS_H__
namespace Ring {
#define MakeRing(Name, Size, Plus, Negate, Multiply, One) \
template < typename T_ > struct Name { \
typedef T_ T; \
enum { size = Size }; \
static T plus(T a, T b) { return Plus; } \
static T negate(T a) { return Negate; } \
static T multiply(T a, T b) { return Multiply; } \
static const T one = One; \
static const T zero = 0; \
}
MakeRing(Z5, 5, (a + b) % 5, (5 - a) % 5, (a * b) % 5, 1);
MakeRing(Z4, 4, (a + b) & 3, (4 - a) & 3, (a * b) & 3, 1);
MakeRing(Z2_2, 4, a^b, a, a&b, 3);
}
#endif