Skip to content

Commit f298320

Browse files
committed
added prototype c module
1 parent 82e3abb commit f298320

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

is_close_module.c

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

setup.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# setup.py for is
2+
from distutils.core import setup, Extension
3+
4+
is_close_module = Extension('is_close_module',
5+
sources=['is_close_module.c'])
6+
7+
setup(name='is_close',
8+
version='1.0',
9+
description='test case of is_close C function',
10+
ext_modules=[is_close_module]
11+
)

0 commit comments

Comments
 (0)