From: Mark Wooding Date: Fri, 27 Feb 2015 14:40:26 +0000 (+0000) Subject: mp.c: Binding for `mp_fibonacci'. X-Git-Tag: 1.1.0~2^2~14 X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/6313f40e5130ed03dcadc0a464865915f07f80ae?ds=sidebyside;hp=9f49c854939cf36901a4a31e43abdb4ea440060f mp.c: Binding for `mp_fibonacci'. --- diff --git a/catacomb-python.h b/catacomb-python.h index a384097..2890289 100644 --- a/catacomb-python.h +++ b/catacomb-python.h @@ -75,6 +75,7 @@ #include #include #include +#include #include #include diff --git a/mp.c b/mp.c index 038324a..1177a60 100644 --- a/mp.c +++ b/mp.c @@ -937,6 +937,15 @@ static PyObject *meth__MP_factorial(PyObject *me, PyObject *arg) return mp_pywrap(x); } +static PyObject *meth__MP_fibonacci(PyObject *me, PyObject *arg) +{ + long i; + mp *x; + if (!PyArg_ParseTuple(arg, "Ol:fibonacci", &me, &i)) return (0); + x = mp_fibonacci(i); + return mp_pywrap(x); +} + #define LOADOP(pre, py, name) \ static PyObject *meth__##py##_##name(PyObject *me, PyObject *arg) \ { \ @@ -2458,6 +2467,8 @@ read a prefix from STR to decide radix: allow `0' for octal, `0x' for hex\n\ or `R_' for other radix R.") METH (_MP_factorial, "\ factorial(I) -> I!: compute factorial") + METH (_MP_fibonacci, "\ +fibonacci(I) -> F(I): compute Fibonacci number") METH (_MP_loadl, "\ loadl(STR) -> X: read little-endian bytes") METH (_MP_loadb, "\