diff --git a/Cargo.toml b/Cargo.toml index 2c21c52..72955be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "highpymath" version = "0.1.1" edition = "2021" license = "MIT" +authors = ["pyrootcpp"] description = "High Quality Rust Python Module" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/highpymath/__init__.py b/highpymath/__init__.py index 9c485b0..f16820a 100644 --- a/highpymath/__init__.py +++ b/highpymath/__init__.py @@ -435,7 +435,7 @@ def calc_pi(return_int: bool = False, return_string: bool = False): pi = calc_pi() -def calc_e(max: int = 1000, return_int: bool = True, return_string: bool = False): +def calc_e(max: int = 10, return_int: bool = True, return_string: bool = False): """ Calculate the euler number. """ diff --git a/highpymath/math.pyx b/highpymath/math.pyx new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..acca09c --- /dev/null +++ b/setup.py @@ -0,0 +1,22 @@ +# setup.py +from setuptools import setup, Extension, find_packages +from setuptools_rust import RustExtension +from Cython.Build import cythonize + +def read(file): + with open(file, 'r') as f: + return f.read() + +setup( + name="highpymath", + version="0.1.1", + packages=find_packages(), + description="High Quality Math library for Python", + author="pyrootcpp", + author_email="pyrootcpp@outlook.de", + long_description=read('README.rst'), + license=read('LICENSE'), + rust_extensions=[RustExtension("highpymath", "Cargo.toml", binding="pyo3")], + ext_modules=cythonize("highpymath/math.pyx"), + zip_safe=False, +) \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 272a464..2719b5a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -174,24 +174,11 @@ fn calc_pi() -> PyResult { Ok(_pi) } -fn facto(n: PyUInt) -> PyUInt { - let mut result = 1; - for i in 1..=n { - let new_result = result * i; - if new_result < result { // Überlaufprüfung - panic!("Integer overflow during factorial calculation"); - } - result = new_result; - } - result -} - #[pyfunction] -fn calc_e(max: PyInt) -> PyResult { - let mut result: PyFloat = 0.0; +fn calc_e(max: PyInt) -> PyResult { + let mut result: PyInt = 0; for i in 0..max { - let factorial_result = facto(i as PyUInt); // Typkonvertierung, falls notwendig - result += 1.0 / factorial_result as PyFloat; // Korrekte Typumwandlung + result += result.checked_mul(i).unwrap(); } Ok(result) }