Mathematics
Last updated
Was this helpful?
Last updated
Was this helpful?
A mathematics library written in GoMelan is available.
To import it see the page.
Calculate the power of an integer to another integer.
Detailed Information:
Parameters:
x
: The base integer.
pow
: The exponent integer.
Return:
Returns x
raised to the power of pow
.
Usage:
Example: power(2, 3)
will return 8
.
Error handling
If x
is 0
, the function returns 0
.
Calculate the absolute value of an integer.
Detailed Information:
Parameter:
x
: The integer to calculate the absolute value for.
Return:
Returns the absolute value of x
.
Usage:
Example: abs(-5)
will return 5
.
Calculate the factorial of an integer.
Detailed Information:
Parameter:
x
: The integer to calculate the factorial for.
Return:
Returns the factorial of x
.
Usage:
Example: factorial(4)
will return 24
.
Error handling
If x
is less than 1
, the function returns x
.
Calculate the sum of an array of integers.
Detailed Information:
Parameter:
a
: An array of integers.
Return:
Returns the sum of the integers in the array.
Usage:
Example: sum([1, 2, 3])
will return 6
.
Determine if a given integer is a prime number.
Detailed Information:
Parameter:
n
: The integer to check for primality.
Return:
Returns true
if n
is a prime number, otherwise returns false
.
Usage:
Example: isPrime(11)
will return true
.
Error handling
If n
is less than or equal to 1
, the function returns false
.