basic functionallity for is odd/even
This commit is contained in:
parent
b84115ce34
commit
8c74e60f54
|
@ -0,0 +1,3 @@
|
|||
from fabelous_math import is_even, is_odd
|
||||
|
||||
print(is_even(5))
|
|
@ -0,0 +1,12 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=42", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "fabelous_math"
|
||||
version = "0.0.1"
|
||||
description = "Math functions written in C++ for faster code"
|
||||
authors = [
|
||||
{name = "Falko Habel", email = "falko.habel@fabelous.app"}
|
||||
]
|
||||
requires-python = ">=3.7"
|
|
@ -0,0 +1,30 @@
|
|||
from setuptools import setup, Extension
|
||||
import platform
|
||||
|
||||
extra_compile_args = []
|
||||
extra_link_args = []
|
||||
|
||||
# Set C++17 flag based on the compiler
|
||||
if platform.system() == "Windows":
|
||||
extra_compile_args.append('/std:c++17')
|
||||
else:
|
||||
extra_compile_args.append('-std=c++17')
|
||||
|
||||
module = Extension(
|
||||
'fabelous_math.simple_functions',
|
||||
sources=[
|
||||
'src/fabelous_math/cpp/functions/simple_functions.cpp',
|
||||
'src/fabelous_math/cpp/functions/bindings.cpp'
|
||||
],
|
||||
include_dirs=['src/fabelous_math/include'],
|
||||
extra_compile_args=extra_compile_args,
|
||||
extra_link_args=extra_link_args,
|
||||
)
|
||||
|
||||
setup(
|
||||
name='fabelous_math',
|
||||
description='Math functions written in C++ for faster code',
|
||||
ext_modules=[module],
|
||||
author="Falko Habel",
|
||||
author_email="falko.habel@fabelous.app"
|
||||
)
|
|
@ -0,0 +1,3 @@
|
|||
from fabelous_math.simple_functions import is_even, is_odd
|
||||
|
||||
__all__ = ["is_even", "is_odd"]
|
|
@ -0,0 +1,36 @@
|
|||
#include <Python.h>
|
||||
#include "simple_functions.hpp"
|
||||
|
||||
static PyObject* is_even_wrapper(PyObject* self, PyObject* args) {
|
||||
long long number;
|
||||
if (!PyArg_ParseTuple(args, "L", &number)) {
|
||||
return NULL;
|
||||
}
|
||||
return PyBool_FromLong(simple_functions::is_even(number));
|
||||
}
|
||||
|
||||
static PyObject* is_odd_wrapper(PyObject* self, PyObject* args) {
|
||||
long long number;
|
||||
if (!PyArg_ParseTuple(args, "L", &number)) {
|
||||
return NULL;
|
||||
}
|
||||
return PyBool_FromLong(simple_functions::is_odd(number));
|
||||
}
|
||||
|
||||
static PyMethodDef NumberUtilsMethods[] = {
|
||||
{"is_even", is_even_wrapper, METH_VARARGS, "Check if a number is even"},
|
||||
{"is_odd", is_odd_wrapper, METH_VARARGS, "Check if a number is odd"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef number_utils_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"simple_functions",
|
||||
"Module for checking if numbers are even or odd",
|
||||
-1,
|
||||
NumberUtilsMethods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_simple_functions(void) {
|
||||
return PyModule_Create(&number_utils_module);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
#include "simple_functions.hpp"
|
||||
|
||||
namespace simple_functions {
|
||||
bool is_even(long long number) {
|
||||
return (number & 1) == 0;
|
||||
}
|
||||
|
||||
bool is_odd(long long number) {
|
||||
return (number & 1) == 1;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
namespace simple_functions {
|
||||
bool is_even(long long number);
|
||||
bool is_odd(long long number);
|
||||
}
|
Loading…
Reference in New Issue