finitefields 0.1.1

Perform algebraic operations between integers over a finite field
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdint.h>
// using namespace std;

uint64_t mul_mod(uint64_t a, uint64_t b, uint64_t m) {
  long double x;
  uint64_t c;
  int64_t r;
  if (a >= m)
    a %= m;
  if (b >= m)
    b %= m;
  x = a;
  c = x * b / m;
  r = (int64_t)(a * b - c * m) % (int64_t)m;
  return r < 0 ? r + m : (uint64_t)r;
}