28 lines
788 B
C++
28 lines
788 B
C++
#include <Python.h>
|
|
#include "pi.hpp"
|
|
|
|
static PyObject* approximate_pi_wrapper(PyObject* self, PyObject* args) {
|
|
long long number;
|
|
if (!PyArg_ParseTuple(args, "L", &number)) { // Changed to 'L' for long long
|
|
return NULL;
|
|
}
|
|
double result = pi::approximate_pi(number); // Change to double
|
|
return PyFloat_FromDouble(result); // Return the actual result as a float
|
|
}
|
|
|
|
static PyMethodDef PiMethods[] = {
|
|
{"approximate_pi", approximate_pi_wrapper, METH_VARARGS, "Calculate the approximation of pi"},
|
|
{NULL, NULL, 0, NULL}
|
|
};
|
|
|
|
static struct PyModuleDef pi_module = {
|
|
PyModuleDef_HEAD_INIT,
|
|
"pi",
|
|
"Module for calculating the approximation of pi",
|
|
-1,
|
|
PiMethods
|
|
};
|
|
|
|
PyMODINIT_FUNC PyInit_pi(void) {
|
|
return PyModule_Create(&pi_module);
|
|
} |