src.pydasa.structs.tools.math#
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#
|
is_prime() checks if a number is prime or not. Original code from Sanjit_Prasad. |
|
next_prime() returns the next prime number greater than n. |
previous_prime() returns the previous prime number less than n. |
|
|
gfactorial() calculates the factorial of a number, including support for floats less than 1.0. |
Module Contents#
- src.pydasa.structs.tools.math.is_prime(n)#
is_prime() checks if a number is prime or not. Original code from Sanjit_Prasad.
- src.pydasa.structs.tools.math.next_prime(n)#
next_prime() returns the next prime number greater than n.
- src.pydasa.structs.tools.math.previous_prime(n)#
previous_prime() returns the previous prime number less than n.
- src.pydasa.structs.tools.math.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).
- Parameters:
- 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.
- Return type:
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