chiark
/
gitweb
/
~mdw
/
catacomb-python
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
eee202c
)
mp.c: Add binding for `leastcongruent' function.
author
Mark Wooding
<mdw@distorted.org.uk>
Thu, 11 May 2017 09:42:15 +0000
(10:42 +0100)
committer
Mark Wooding
<mdw@distorted.org.uk>
Sun, 14 May 2017 03:31:03 +0000
(
04:31
+0100)
mp.c
patch
|
blob
|
blame
|
history
diff --git
a/mp.c
b/mp.c
index 79c6cf20c8952f6502f68395d28abeab2ebe0202..88ee73813b538baa863097df8f07232a4fe66523 100644
(file)
--- a/
mp.c
+++ b/
mp.c
@@
-682,6
+682,19
@@
end:
return (z);
}
return (z);
}
+static PyObject *mpmeth_leastcongruent(PyObject *me, PyObject *arg)
+{
+ mp *z, *b, *m;
+ PyObject *rc = 0;
+
+ if (!PyArg_ParseTuple(arg, "O&O&:leastcongruent", convmp, &b, convmp, &m))
+ goto end;
+ z = mp_leastcongruent(MP_NEW, b, MP_X(me), m);
+ rc = mp_pywrap(z);
+end:
+ return (rc);
+}
+
#define STOREOP(name, c) \
static PyObject *mpmeth_##name(PyObject *me, \
PyObject *arg, PyObject *kw) \
#define STOREOP(name, c) \
static PyObject *mpmeth_##name(PyObject *me, \
PyObject *arg, PyObject *kw) \
@@
-792,6
+805,8
@@
static PyMethodDef mp_pymethods[] = {
"X.gcdx(Y) -> (gcd(X, Y), U, V) with X U + Y V = gcd(X, Y)")
METH (modinv, "X.modinv(Y) -> multiplicative inverse of Y mod X")
METH (modsqrt, "X.modsqrt(Y) -> square root of Y mod X, if X prime")
"X.gcdx(Y) -> (gcd(X, Y), U, V) with X U + Y V = gcd(X, Y)")
METH (modinv, "X.modinv(Y) -> multiplicative inverse of Y mod X")
METH (modsqrt, "X.modsqrt(Y) -> square root of Y mod X, if X prime")
+ METH (leastcongruent,
+ "X.leastcongruent(B, M) -> smallest Z >= B with Z == X (mod M)")
KWMETH(primep, "X.primep(rng = rand) -> true/false if X is prime")
KWMETH(tostring, "X.tostring(radix = 10) -> STR")
KWMETH(storel, "X.storel(len = -1) -> little-endian bytes")
KWMETH(primep, "X.primep(rng = rand) -> true/false if X is prime")
KWMETH(tostring, "X.tostring(radix = 10) -> STR")
KWMETH(storel, "X.storel(len = -1) -> little-endian bytes")