|
| 1 | +/* is_close implimentation in C */ |
| 2 | + |
| 3 | +#include "Python.h" |
| 4 | + |
| 5 | +char *is_close_doc = "This will be the docstring, when I write it"; |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +static PyObject * |
| 10 | +is_close_c(PyObject *self, PyObject *args, PyObject *kwargs) |
| 11 | +{ |
| 12 | + double a, b; |
| 13 | + double rel_tol = 1e-9; |
| 14 | + double abs_tol = 0.0; |
| 15 | + long result = 0; |
| 16 | + |
| 17 | + static char *keywords[] = {"a", "b", "rel_tol", "abs_tol", NULL}; |
| 18 | + |
| 19 | + |
| 20 | + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "dd|dd:is_close", |
| 21 | + keywords, |
| 22 | + &a, &b, &rel_tol, &abs_tol |
| 23 | + )) |
| 24 | + return NULL; |
| 25 | + |
| 26 | + result = 1; |
| 27 | + |
| 28 | + return PyBool_FromLong(result); |
| 29 | +} |
| 30 | + |
| 31 | +static PyMethodDef IsCloseMethods[] = { |
| 32 | + {"is_close", is_close_c, METH_VARARGS | METH_KEYWORDS, |
| 33 | + "determine if two floating point numbers are close"}, |
| 34 | + {NULL, NULL, 0, NULL} /* Sentinel */ |
| 35 | +}; |
| 36 | + |
| 37 | +static struct PyModuleDef is_close_module = { |
| 38 | + PyModuleDef_HEAD_INIT, |
| 39 | + "is_close_module", /* name of module */ |
| 40 | + "docstring for is_close", /* module documentation, may be NULL */ |
| 41 | + -1, /* size of per-interpreter state of the module, |
| 42 | + or -1 if the module keeps state in global variables. */ |
| 43 | + IsCloseMethods |
| 44 | +}; |
| 45 | + |
| 46 | +PyMODINIT_FUNC |
| 47 | +PyInit_is_close_module(void) |
| 48 | +{ |
| 49 | + return PyModule_Create(&is_close_module); |
| 50 | +} |
0 commit comments