Skip to content

Commit bad95b8

Browse files
committed
Update
1 parent 8d8aafb commit bad95b8

File tree

2 files changed

+87
-10
lines changed

2 files changed

+87
-10
lines changed

highpymath/__init__.py

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
from .highpymath import sum as _sum
2-
from .highpymath import sub as _sub
3-
from .highpymath import mul as _mul
4-
from .highpymath import div as _div
5-
from .highpymath import exp as _exp
6-
from .highpymath import sqrt as _sqrt
7-
from .highpymath import log as _log
81
from .highpymath import MathValueError as _mve
9-
from .highpymath import factorial as _factorial
10-
from .highpymath import reciprocal as _reciprocal
112

12-
__all__ = ['sum', 'sub', 'mul', 'div', 'MathValueError', 'exp', 'sqrt', 'log', 'reciprocal']
3+
__all__ = ['sum', 'sub', 'mul', 'div', 'MathValueError', 'exp', 'sqrt', 'log', 'reciprocal', 'factorial', 'linear']
134

145
class MathValueError(_mve):
156
"""
@@ -27,6 +18,7 @@ def sum(a: any, b: any, return_int: bool = False, return_string: bool = False):
2718
"""
2819
Create the Summary of 2 Numbers.
2920
"""
21+
from .highpymath import sum as _sum
3022
return_float = True
3123
if return_int:
3224
return_float = False
@@ -51,6 +43,7 @@ def sub(a: any, b: any, return_int: bool = False, return_string: bool = False):
5143
"""
5244
Create the Subtraction of 2 Numbers.
5345
"""
46+
from .highpymath import sub as _sub
5447
return_float = True
5548
if return_int:
5649
return_float = False
@@ -75,6 +68,7 @@ def mul(a: any, b: any, return_int: bool = False, return_string: bool = False):
7568
"""
7669
Create the Multiplication of 2 Numbers.
7770
"""
71+
from .highpymath import mul as _mul
7872
return_float = True
7973
if return_int:
8074
return_float = False
@@ -99,6 +93,7 @@ def div(a: any, b: any, return_int: bool = False, return_string: bool = False):
9993
"""
10094
Create the Division of 2 Numbers.
10195
"""
96+
from .highpymath import div as _div
10297
return_float = True
10398
if return_int:
10499
return_float = False
@@ -123,6 +118,7 @@ def exp(base: any, power: any, return_int: bool = False, return_string: bool = F
123118
"""
124119
Create the Exponentiation of 2 Numbers.
125120
"""
121+
from .highpymath import exp as _exp
126122
return_float = True
127123
if return_int:
128124
return_float = False
@@ -147,6 +143,7 @@ def sqrt(base: any, power: any = 2, return_int: bool = False, return_string: boo
147143
"""
148144
Create the Square Root of a Number.
149145
"""
146+
from .highpymath import sqrt as _sqrt
150147
return_float = True
151148
if return_int:
152149
return_float = False
@@ -171,6 +168,7 @@ def log(base: any, power: any = 10, return_int: bool = False, return_string: boo
171168
"""
172169
Create the Logarithm of a Number.
173170
"""
171+
from .highpymath import log as _log
174172
return_float = True
175173
if return_int:
176174
return_float = False
@@ -195,6 +193,7 @@ def reciprocal(a: any, return_int: bool = False, return_string: bool = False):
195193
"""
196194
Create the Reciprocal of a Number.
197195
"""
196+
from .highpymath import reciprocal as _reciprocal
198197
return_float = True
199198
if return_int:
200199
return_float = False
@@ -215,12 +214,69 @@ def factorial(a: int, return_int: bool = False, return_string: bool = False):
215214
"""
216215
Get the Factorial from a Number.
217216
"""
217+
from .highpymath import factorial as _factorial
218218
return_float = True
219219
if return_int:
220220
return_float = False
221221
if not isinstance(a, int):
222222
raise MathValueError("a must be an integer")
223223
_result = _factorial(a=a)
224+
if return_int:
225+
_result = int(_result)
226+
elif return_float:
227+
_result = float(_result)
228+
if return_string:
229+
_result = str(_result)
230+
return _result
231+
232+
def linear(a: any = None, b: any = None, c: any = None, search_a: bool = False, search_b: bool = False, search_c: bool = False, return_int: bool = False, return_string: bool = False):
233+
"""
234+
Solve the Linear Function from type: a + b = c
235+
"""
236+
from .highpymath import linear_base_a as _linear_base_a
237+
from .highpymath import linear_base_b as _linear_base_b
238+
from .highpymath import linear_base_c as _linear_base_c
239+
return_float = True
240+
if return_int:
241+
return_float = False
242+
if search_a and search_b and search_c:
243+
raise MathValueError("You need to specify one of the 3 arguments")
244+
if search_a and search_b:
245+
raise MathValueError("You need to specify one of the 3 arguments")
246+
if search_a and search_c:
247+
raise MathValueError("You need to specify one of the 3 arguments")
248+
if search_b and search_c:
249+
raise MathValueError("You need to specify one of the 3 arguments")
250+
if search_a:
251+
if not isinstance(b, (int, float)):
252+
raise MathValueError("b must be a number")
253+
if not isinstance(c, (int, float)):
254+
raise MathValueError("c must be a number")
255+
if isinstance(b, int):
256+
b = float(b)
257+
if isinstance(c, int):
258+
c = float(c)
259+
_result = _linear_base_a(b=b, c=c)
260+
elif search_b:
261+
if not isinstance(a, (int, float)):
262+
raise MathValueError("a must be a number")
263+
if not isinstance(c, (int, float)):
264+
raise MathValueError("c must be a number")
265+
if isinstance(a, int):
266+
a = float(a)
267+
if isinstance(c, int):
268+
c = float(c)
269+
_result = _linear_base_b(a=a, c=c)
270+
elif search_c:
271+
if not isinstance(a, (int, float)):
272+
raise MathValueError("a must be a number")
273+
if not isinstance(b, (int, float)):
274+
raise MathValueError("b must be a number")
275+
if isinstance(a, int):
276+
a = float(a)
277+
if isinstance(b, int):
278+
b = float(b)
279+
_result = _linear_base_c(a=a, b=b)
224280
if return_int:
225281
_result = int(_result)
226282
elif return_float:

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ fn factorial(a: PyInt) -> PyResult<PyInt> {
9292
}
9393
}
9494

95+
#[pyfunction]
96+
/// Berechnet die Summe von `a` und `b`. bei Gleichungen a + b = c
97+
fn linear_base_c(a: PyFloat, b: PyFloat) -> PyResult<PyFloat> {
98+
Ok(a + b)
99+
}
100+
101+
#[pyfunction]
102+
/// Berechnet `c` minus `a`, um `b` zu isolieren. bei Gleichungen a + b = c
103+
fn linear_base_b(a: PyFloat, c: PyFloat) -> PyResult<PyFloat> {
104+
Ok(c - a)
105+
}
106+
107+
#[pyfunction]
108+
/// Berechnet `c` minus `b`, um `a` zu isolieren. bei Gleichungen a + b = c
109+
fn linear_base_a(b: PyFloat, c: PyFloat) -> PyResult<PyFloat> {
110+
Ok(c - b)
111+
}
112+
95113
/// A Python module implemented in Rust.
96114
#[pymodule]
97115
fn highpymath(m: &PyModule) -> PyResult<()> {
@@ -104,6 +122,9 @@ fn highpymath(m: &PyModule) -> PyResult<()> {
104122
m.add_function(wrap_pyfunction!(log, m)?)?;
105123
m.add_function(wrap_pyfunction!(factorial, m)?)?;
106124
m.add_function(wrap_pyfunction!(reciprocal, m)?)?;
125+
m.add_function(wrap_pyfunction!(linear_base_c, m)?)?;
126+
m.add_function(wrap_pyfunction!(linear_base_b, m)?)?;
127+
m.add_function(wrap_pyfunction!(linear_base_a, m)?)?;
107128
m.add("MathValueError", m.py().get_type::<MathValueError>())?;
108129
Ok(())
109130
}

0 commit comments

Comments
 (0)