Skip to content

Commit 09b6074

Browse files
committed
Update
1 parent 42f1c8e commit 09b6074

File tree

1 file changed

+7
-81
lines changed

1 file changed

+7
-81
lines changed

README.rst

+7-81
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,15 @@
11
highpymath
22
==========
33

4-
This is a Python library for high-quality mathematical calculations.
4+
High high-quality Python Math Library written in Rust and Python.
55

6-
Language
6+
Features
77
========
88

9-
This library is written in Rust and Python, combining the performance of Rust with the ease of use of Python.
9+
Better precision
10+
Better performance
11+
Better readability
1012

11-
The main implementation for calculations is in Rust, while Python is used to write user-facing functions. This approach ensures efficient computation with user-friendly interfaces.
13+
The Main Functions are Implemented in Rust, but you can not call direct the Rust Functions, this will do in Python written wrapper Functions.
1214

13-
Python Wrapper Functions
14-
========================
15-
16-
The Python wrapper functions enhance the conversion between Python and Rust, making it easier for users to utilize the core Rust implementations. These wrappers add flexibility by allowing various input types and output formats.
17-
18-
Example: The `sqrt` Function
19-
---------------------------
20-
21-
Let's examine the `sqrt` function, which calculates the root of a number based on the specified power.
22-
23-
Rust Implementation:
24-
--------------------
25-
26-
.. code-block:: rust
27-
28-
#[pyfunction]
29-
fn sqrt(base: f32, power: f32) -> PyResult<f32> {
30-
if base < 0.0 && power % 2.0 == 0.0 {
31-
Err(MathValueError::new_err("Negative base for even power"))
32-
} else {
33-
Ok(base.powf(1.0 / power))
34-
}
35-
}
36-
37-
This Rust function accepts only floating-point numbers and returns a float as a result. It handles errors for cases where the base is negative and the power is even, as these conditions would result in a non-real number.
38-
39-
Python Wrapper Implementation:
40-
------------------------------
41-
42-
.. code-block:: python
43-
44-
# __init__.py
45-
46-
from .highpymath import sqrt as _sqrt # Import sqrt as a private function
47-
48-
def sqrt(base: any, power: any, return_int: bool = False, return_string: bool = False):
49-
"""
50-
Calculate the root of a number with specified power.
51-
Allows for returning results as integer or string.
52-
"""
53-
if not isinstance(base, (int, float)):
54-
raise MathValueError("Base must be a numeric type")
55-
if not isinstance(power, (int, float)):
56-
raise MathValueError("Power must be a numeric type")
57-
58-
base = float(base)
59-
power = float(power)
60-
result = _sqrt(base=base, power=power)
61-
62-
if return_int:
63-
result = int(result)
64-
elif return_string:
65-
result = str(result)
66-
return result
67-
68-
Usage Examples:
69-
---------------
70-
71-
.. code-block:: bash
72-
73-
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] on linux
74-
>>> import highpymath as math
75-
>>> math.sqrt(81, 2)
76-
9.0
77-
>>> math.sqrt(81, 2, return_string=True)
78-
'9.0'
79-
>>> math.sqrt(81, 2, return_int=True)
80-
9
81-
>>> math.sqrt(81, 2, return_int=True, return_string=True)
82-
'9'
83-
84-
This section provides practical examples of how to use the `sqrt` function with different settings for return types.
85-
86-
Conclusion
87-
==========
88-
89-
The `highpymath` library offers a robust solution for mathematical calculations by leveraging the strengths of both Rust and Python. It is designed to be both efficient and user-friendly, accommodating a wide range of user requirements.
15+
The in Python Written Wrapper Functions gives you a gurenteed better performance and precision.

0 commit comments

Comments
 (0)