NumericConditions extension

A collection of extension methods for numeric types that provide various mathematical and comparison operations.

This extension adds functionality to check numeric properties and perform mathematical calculations on numbers. It includes methods for:

  • Comparison operations (greater than, less than, etc.)
  • Number properties (even, odd, prime, etc.)
  • Mathematical operations (square root, power)

Example usage:

void main() { int number = 7; print(number.isPositive()); // true print(number.isPrime()); // true print(number.isBetween(1, 10)); // true }

on

Methods

isBetween(num min, num max) bool

Available on num, provided by the NumericConditions extension

Returns whether this number falls within the range min to max, inclusive.
isDivisibleBy(num divisor) bool

Available on num, provided by the NumericConditions extension

Returns whether this number is evenly divisible by divisor.
isEven() bool

Available on num, provided by the NumericConditions extension

Returns whether this number is even.
isGreaterOrEqual(num value) bool

Available on num, provided by the NumericConditions extension

Returns whether this number is greater than or equal to value.
isGreaterThan(num value) bool

Available on num, provided by the NumericConditions extension

Returns whether this number is greater than value.
isLessOrEqual(num value) bool

Available on num, provided by the NumericConditions extension

Returns whether this number is less than or equal to value.
isLessThan(num value) bool

Available on num, provided by the NumericConditions extension

Returns whether this number is less than value.
isMultipleOf(num factor) bool

Available on num, provided by the NumericConditions extension

Returns whether this number is a multiple of factor.
isNegative() bool

Available on num, provided by the NumericConditions extension

Returns whether this number is negative (less than zero).
isOdd() bool

Available on num, provided by the NumericConditions extension

Returns whether this number is odd.
isPerfectSquare() bool

Available on num, provided by the NumericConditions extension

Returns whether this number is a perfect square.
isPositive() bool

Available on num, provided by the NumericConditions extension

Returns whether this number is positive (greater than zero).
isPrime() bool

Available on num, provided by the NumericConditions extension

Returns whether this number is prime.
isZero() bool

Available on num, provided by the NumericConditions extension

Returns whether this number is exactly zero.
pow(num exponent) num

Available on num, provided by the NumericConditions extension

Returns this number raised to the power of exponent.
sqrt() double

Available on num, provided by the NumericConditions extension

Returns the square root of this number.