Macaulay2 Engine
Loading...
Searching...
No Matches

◆ add()

void M2::ARingGFM2::add ( elem & result,
elem a,
elem b ) const
inline

Definition at line 258 of file aring-m2-gf.hpp.

259 {
260 if (a == 0)
261 result = b;
262 else if (b == 0)
263 result = a;
264 else
265 {
266 int n = a - b;
267 if (n > 0)
268 {
269 if (n == mGF.minusOne())
270 result = 0;
271 else
272 result = modulus_add(b, mGF.oneTable(n), mGF.orderMinusOne());
273 }
274 else if (n < 0)
275 {
276 if (-n == mGF.minusOne())
277 result = 0;
278 else
279 result = modulus_add(a, mGF.oneTable(-n), mGF.orderMinusOne());
280 }
281 else
282 {
283 if (mGF.characteristic() == 2)
284 result = 0;
285 else
286 result =
287 modulus_add(a, mGF.oneTable(mGF.one()), mGF.orderMinusOne());
288 }
289 }
290 }
GaloisFieldTable mGF
static int modulus_add(int a, int b, int p)
Arithmetic functions ///////.
VALGRIND_MAKE_MEM_DEFINED & result(result)

References mGF, modulus_add(), and result().

Referenced by fromSmallIntegerCoefficients(), and subtract().