-
Abs: Returns the absolute value of the given number. Works for both integers and floating-point numbers. If the input is negative, it returns its positive equivalent; otherwise, it returns the number as is.
-
Sign: Determines the sign of a signed number. Returns
1if the number is positive,-1if negative, and0if the number is zero. -
Min: Returns the smaller of two numbers. Works for all number types including integers and floating-point numbers.
-
Max: Returns the larger of two numbers. Works for all number types including integers and floating-point numbers.
-
Clamp: Restricts a given value to be within a specified range. If the value is below the minimum, it returns the minimum; if above the maximum, it returns the maximum.
-
IntPow: Calculates base raised to the power of exp. Supports both positive and negative exponents. Returns float64 for fractional results.
-
IsEven: Checks if the given integer is even. Returns
truefor even numbers andfalseotherwise. -
IsOdd: Checks if the given integer is odd. Returns
truefor odd numbers andfalseotherwise. -
Swap: Swaps the values of two variables in place. It uses pointers to modify the original variables.
-
Factorial: Computes the factorial of a non-negative integer. Factorial of
nis defined as the product of all integers from1ton. For0and1, the result is1. Factorial returns an error on invalid input. -
GCD: Finds the greatest common divisor (GCD) of two integers using the Euclidean algorithm. If one of the inputs is
0, the other input is returned. -
LCM: Finds the least common multiple (LCM) of two integers.
-
Sqrt: Finds the square root of the given number. Works for both integers and floating-point numbers. If the input is negative, it returns an error along with the original negative number.
-
IsPrime: Checks if a number is prime or not. Only works for non-negative integers.
-
PrimeList: Returns a slice of prime numbers up to n.
-
GetDivisors: Returns the divisors of a positive integer as an unordered slice. Returns an empty slice for negative inputs.
-
RoundDecimalPlaces: Rounds a float64 to the specified number of decimal places using
math.Round(half away from zero). Negative values forplacesare clamped to0(i.e., rounds to a whole number).
For examples of each function, please checkout EXAMPLES.md