Number Checkers
Predicate functions to check/compare numbers.
Predicate functions to check/compare numbers. These functions return true or false.
isPrime
Determines whether a given number is a prime number using an efficient 6k ± 1 optimization.
Function Signature
isPrime(number: number): boolean;Parameters
number— The integer to evaluate for prime number check.
Returns
trueif the number is a prime, otherwisefalse.
Examples
Notes
- Uses a fast prime number check based on:
- Simple divisibility rules for 2 and 3.
6k ± 1optimization to reduce unnecessary checks.
- Returns
falsefor all numbers below 2. - Ideal for performance on small to moderate integers.
isEven
Checks if a number is even (divisible by 2).
Function Signature
isEven(input: Numeric): boolean;Parameters
input: The number or numeric string to check.
Returns
Returns true if the number is even, otherwise false.
Notes
- Handles both number and numeric string inputs.
- Returns
falsefor non-numeric strings and non-finite numbers orNaN.
Example
isOdd
Checks if a number is odd (not divisible by 2).
Function Signature
isOdd(input: Numeric): boolean;Parameters
input: The number or numeric string to check.
Returns
Returns true if the number is odd, otherwise false.
Notes
- Handles both number and numeric string inputs.
- Returns
falsefor non-numeric strings and non-finite numbers orNaN.
Example
isMultiple
Checks if a number is a multiple of another number.
Function Signature
isMultiple(input: number, multipleOf: number): boolean;Parameters
input: The number to check.multipleOf: The potential multiple.
Returns
Returns true if input is a multiple of multipleOf, otherwise false.
Example
Notes
- Returns
truewheninputis 0 andmultipleOfis 0 (mathematically undefined case) - Handles negative numbers correctly
isPerfectSquare
Checks if a number is a perfect square.
Function Signature
isPerfectSquare(num: number): boolean;Parameters
num: The number to check.
Returns
Returns true if the number is a perfect square, otherwise false.
Example
isFibonacci
Checks if a number is part of the Fibonacci sequence.
Function Signature
isFibonacci(num: number): boolean;Parameters
num: The number to check.
Returns
Returns true if the number is in the Fibonacci sequence, otherwise false.
Example
Algorithm
Uses the mathematical property that a number n is Fibonacci if and only if one or both of (5*n^2 + 4) or (5*n^2 - 4) is a perfect square.
areInvalidNumbers
Checks if any input is not a finite number.
Function Signature
areInvalidNumbers(...numbers: number[]): boolean;Parameters
numbers: Spread of numbers to validate.
Returns
Returns true if any input is not finite (NaN, Infinity, etc.), otherwise false.
Example
Common Use Cases
- Validating user input
- Sanity checking before mathematical operations
- Data quality verification
Notes
- Returns
truefor:NaNInfinity-Infinity- Non-number values
- Returns
falsefor all finite numbers including zero
Aliases
| Function Name | Alias |
|---|---|
isPrime | isPrimeNumber |
isEven | isEvenNumber |
isOdd | isOddNumber |
isMultiple | isMultipleOf |
isFibonacci | isPartOfFibonacci, isPartOfFibonacciSeries |
areInvalidNumbers | areNumbersInvalid, isInvalidNumber, isNumberInvalid |
Last updated: Tue, Jun 09, 2026 04:51:46AM (UTC)
