11from .highpymath import MathValueError as _mve
22
3- __all__ = ['sum' , 'sub' , 'mul' , 'div' , 'MathValueError' , 'exp' , 'sqrt' , 'log' , 'reciprocal' , 'factorial' , 'linear ' , 'cpi ' ]
3+ __all__ = ['sum' , 'sub' , 'mul' , 'div' , 'MathValueError' , 'exp' , 'sqrt' , 'log' , 'reciprocal' , 'factorial' , 'calc_pi ' , 'calc_e ' ]
44
55class MathValueError (_mve ):
66 """
@@ -229,62 +229,6 @@ def factorial(a: int, return_int: bool = False, return_string: bool = False):
229229 _result = str (_result )
230230 return _result
231231
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 )
280- if return_int :
281- _result = int (_result )
282- elif return_float :
283- _result = float (_result )
284- if return_string :
285- _result = str (_result )
286- return _result
287-
288232def sin (a : any , return_int : bool = False , return_string : bool = False ):
289233 """
290234 Create the Sinus of a Number.
@@ -435,15 +379,19 @@ def calc_pi(return_int: bool = False, return_string: bool = False):
435379
436380pi = calc_pi ()
437381
438- def calc_e (max : int = 1000 , return_int : bool = True , return_string : bool = False ):
382+ def calc_e (max : int = 20 , return_int : bool = False , return_string : bool = False ):
439383 """
440384 Calculate the euler number.
441385 """
442- from .highpymath import calc_e as _calc_e
386+ from .highpymath import factorial as _fact
443387 return_float = True
444388 if return_int :
445389 return_float = False
446- _result = _calc_e (max = max )
390+ _result = 0
391+ i = 0
392+ while i < max :
393+ _result += 1 / _fact (i )
394+ i += 1
447395 if return_int :
448396 _result = int (_result )
449397 elif return_float :
@@ -452,4 +400,152 @@ def calc_e(max: int = 1000, return_int: bool = True, return_string: bool = False
452400 _result = str (_result )
453401 return _result
454402
455- e = calc_e ()
403+ e = calc_e ()
404+
405+ class equation :
406+ """
407+ Class to Solve equations.
408+ """
409+ @staticmethod
410+ def quadratic (a : any , b : any , c : any = None , use_pq : bool = False , return_int : bool = False , return_string : bool = False ) -> tuple :
411+ """
412+ Function to Solve a Quadratic Equation.
413+ Attention:
414+ - If you use use_pq = True, a will be used as p and b will be used as q.
415+ - If you use use_pq = False, a will be used as a, b will be used as b and c will be used as c.
416+ """
417+ from .highpymath import quadratic_base as _base
418+ from .highpymath import quadratic_pq as _pq
419+ return_float = True
420+ if return_int :
421+ return_float = False
422+ if not isinstance (a , (int , float )):
423+ raise MathValueError ("a must be a Number" )
424+ if not isinstance (b , (int , float )):
425+ raise MathValueError ("b must be a Number" )
426+ if not use_pq and c is None :
427+ raise MathValueError ("c is set as None, but you don't use pq" )
428+ if not use_pq and not isinstance (c , (int , float )):
429+ raise MathValueError ("c must be a Number" )
430+ if isinstance (a , int ):
431+ a = float (a )
432+ if isinstance (b , int ):
433+ b = float (b )
434+ if not use_pq and isinstance (c , int ):
435+ c = float (c )
436+ if use_pq :
437+ p = a
438+ q = b
439+ if not use_pq :
440+ _result = _base (a = a , b = b , c = c )
441+ else :
442+ _result = _pq (p = p , q = q )
443+ _result1 = _result [0 ]
444+ _result2 = _result [1 ]
445+ if return_int :
446+ _result1 = int (_result1 )
447+ _result2 = int (_result2 )
448+ elif return_float :
449+ _result1 = float (_result1 )
450+ _result2 = float (_result2 )
451+ if return_string :
452+ _result1 = str (_result1 )
453+ _result2 = str (_result2 )
454+ return _result1 , _result2
455+
456+ @staticmethod
457+ 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 ):
458+ """
459+ Solve the Linear Function from type: a + b = c
460+ """
461+ from .highpymath import linear_base_a as _linear_base_a
462+ from .highpymath import linear_base_b as _linear_base_b
463+ from .highpymath import linear_base_c as _linear_base_c
464+ return_float = True
465+ if return_int :
466+ return_float = False
467+ if search_a and search_b and search_c :
468+ raise MathValueError ("You need to specify one of the 3 arguments" )
469+ if search_a and search_b :
470+ raise MathValueError ("You need to specify one of the 3 arguments" )
471+ if search_a and search_c :
472+ raise MathValueError ("You need to specify one of the 3 arguments" )
473+ if search_b and search_c :
474+ raise MathValueError ("You need to specify one of the 3 arguments" )
475+ if search_a :
476+ if not isinstance (b , (int , float )):
477+ raise MathValueError ("b must be a number" )
478+ if not isinstance (c , (int , float )):
479+ raise MathValueError ("c must be a number" )
480+ if isinstance (b , int ):
481+ b = float (b )
482+ if isinstance (c , int ):
483+ c = float (c )
484+ _result = _linear_base_a (b = b , c = c )
485+ elif search_b :
486+ if not isinstance (a , (int , float )):
487+ raise MathValueError ("a must be a number" )
488+ if not isinstance (c , (int , float )):
489+ raise MathValueError ("c must be a number" )
490+ if isinstance (a , int ):
491+ a = float (a )
492+ if isinstance (c , int ):
493+ c = float (c )
494+ _result = _linear_base_b (a = a , c = c )
495+ elif search_c :
496+ if not isinstance (a , (int , float )):
497+ raise MathValueError ("a must be a number" )
498+ if not isinstance (b , (int , float )):
499+ raise MathValueError ("b must be a number" )
500+ if isinstance (a , int ):
501+ a = float (a )
502+ if isinstance (b , int ):
503+ b = float (b )
504+ _result = _linear_base_c (a = a , b = b )
505+ if return_int :
506+ _result = int (_result )
507+ elif return_float :
508+ _result = float (_result )
509+ if return_string :
510+ _result = str (_result )
511+ return _result
512+
513+ equation = equation ()
514+
515+ __all__ .append ('equation' )
516+
517+ def sqrt2 (base : any , return_int : bool = False , return_string : bool = False ):
518+ """
519+ Calculate the Square Root of a Number.
520+ """
521+ from .highpymath import sqrt2 as _sqrt2
522+ return_float = True
523+ if return_int :
524+ return_float = False
525+ _result = _sqrt2 (base = base )
526+ if return_int :
527+ _result = int (_result )
528+ elif return_float :
529+ _result = float (_result )
530+ if return_string :
531+ _result = str (_result )
532+ return _result
533+
534+ __all__ .append ('sqrt2' )
535+
536+ def exp2 (base : any , return_int : bool = False , return_string : bool = False ):
537+ """
538+ Calculate the Exponentiation of a Number.
539+ """
540+ from .highpymath import exp2 as _exp2
541+ return_float = True
542+ if return_int :
543+ return_float = False
544+ _result = _exp2 (base = base )
545+ if return_int :
546+ _result = int (_result )
547+ elif return_float :
548+ _result = float (_result )
549+ if return_string :
550+ _result = str (_result )
551+ return _result
0 commit comments