src.pydasa.structs.tools.math ============================= .. py:module:: src.pydasa.structs.tools.math .. autoapi-nested-parse:: Module math.py =========================================== Module with math functions for finding prime numbers and calculating factorials. in *PyDASA*. Module with math functions for handling data in the for Separate Chaining Hash Table. *IMPORTANT:* based on the implementations proposed by the following authors/books: #. Algorithms, 4th Edition, Robert Sedgewick and Kevin Wayne. #. Data Structure and Algorithms in Python, M.T. Goodrich, R. Tamassia, M.H. Goldwasser. *NOTE:* code contributed by Sanjit_Prasad in https://www.geeksforgeeks.org/prime-numbers/ Functions --------- .. autoapisummary:: src.pydasa.structs.tools.math.is_prime src.pydasa.structs.tools.math.next_prime src.pydasa.structs.tools.math.previous_prime src.pydasa.structs.tools.math.gfactorial Module Contents --------------- .. py:function:: is_prime(n) *is_prime()* checks if a number is prime or not. Original code from Sanjit_Prasad. :param n: number to check if it is prime. :type n: int :returns: True if the number is prime, False otherwise. :rtype: bool .. py:function:: next_prime(n) *next_prime()* returns the next prime number greater than n. :param n: number to check if it is prime. :type n: int :returns: the next prime number greater than n. :rtype: int .. py:function:: previous_prime(n) *previous_prime()* returns the previous prime number less than n. :param n: number to check if it is prime. :type n: int :returns: the previous prime number less than n. :rtype: int .. py:function:: gfactorial(x, prec = None) *gfactorial()* calculates the factorial of a number, including support for floats less than 1.0. - For integers n ≥ 0: Returns n! (n factorial). - For floats x: Returns Γ(x+1) (gamma function). :param x: The number to compute the factorial for. :type x: Union[int, float] :param prec: precision, or the number of decimal places to round the result to. Defaults to None. :type prec: Optional[int], optional :raises ValueError: If x is a negative integer. :returns: The factorial of x. Returns an integer for integer inputs ≥ 0, and a float for float inputs or integers < 0. :rtype: Union[int, float] .. rubric:: Examples >>> gfactorial(5) 120 >>> gfactorial(0) 1 >>> gfactorial(0.5) # Equivalent to Γ(1.5) = 0.5 * Γ(0.5) = 0.5 * √Pi 0.8862269254527579 >>> gfactorial(-0.5) # Equivalent to Γ(0.5) = √Pi 1.7724538509055159