mp.c: Binding for `mp_fibonacci'.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 27 Feb 2015 14:40:26 +0000 (14:40 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 27 Feb 2015 14:40:26 +0000 (14:40 +0000)
catacomb-python.h
mp.c

index a384097..2890289 100644 (file)
@@ -75,6 +75,7 @@
 #include <catacomb/mpmont.h>
 #include <catacomb/mpbarrett.h>
 #include <catacomb/mpreduce.h>
+#include <catacomb/mp-fibonacci.h>
 
 #include <catacomb/pgen.h>
 #include <catacomb/pfilt.h>
diff --git a/mp.c b/mp.c
index 038324a..1177a60 100644 (file)
--- 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,             "\