Math class

The Math class provides a collection of common mathematical constants, functions and utilities, inspired by the dart:math library. This class provides additional functionality, such as methods for generating pseudo-random values and a function for mapping a value from one range to another.

Constructors

Math()
Factory constructor to ensure exception. Throws an exception if an attempt is made to instantiate this class.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

abs<T extends num>(T value) → T
Computes and returns an absolute value for the number specified by value.
ceil(double value, [bool keepDouble = true]) num
Returns the ceiling of the specified value or expression. Parameter keepDouble enforces the return type to be double.
dotProduct(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3) double
Computes the dot product of two 2D vectors.
floor(double value, [bool keepDouble = true]) num
Returns the floor of the number or expression specified in the parameter value. Parameter keepDouble enforces the return type to be double.
lerp(num min, num max, double t) double
Linearly interpolates a value within a given range.
log10(num value) double
Log base 10
map(double srcValue, double srcMin, double srcMax, double dstMin, double dstMax) double
Maps a value from one range to another.
norm(num value, num min, num max) double
Normalizes a value within a given range.
random() double
Returns a pseudo-random double n, where 0 <= n < 1. Using the math.Random class.
randomBool() bool
Returns a pseudo-random boolean (true or false). Using the math.Random class.
randomList<E>(List<E> list) → E
Returns a pseudo-random element <E> from the parameter list. Using the Random() class to compute the List index.
randomRange(num min, num max) double
Returns a pseudo-random double number between parameters min and max. Doesn't check for errors: Parameters can not be null; And min > max.
randomRangeClamp(num min, num max, num clamp) double
Returns a pseudo-random double number between parameters min and max, clamping the returned value to clamp. Doesn't check for errors: Parameters can not be null; And min > max.
randomRangeInt(num min, num max) int
Returns a pseudo-random int number between parameters min and max. Doesn't check for errors: Parameters can not be null; And min > max.
randomRangeIntClamp(num min, num max, num clamp) int
Returns a pseudo-random int number between parameters min and max, clamping the returned value to clamp. Doesn't check for errors: Parameters can not be null; And min > max.
round(double value, [bool keepDouble = true]) num
Rounds the valueup or down to the nearest integer and returns the value. Parameter keepDouble enforces the return type to be double.

Constants

acos → const double Function(num x)
Computes and returns the arc cosine of the number specified in the parameter x, in radians.
asin → const double Function(num x)
Computes and returns the arc sine of the number specified in the parameter x, in radians.
atan → const double Function(num x)
Computes and returns the value, in radians, of the angle whose tangent is specified in the parameter x. Shortcut of math.atan
atan2 → const double Function(num a, num b)
Computes and returns the angle of the point a/b in radians, in cartesian coordinates a=y, and b=x. when measured counterclockwise from a circle's x axis (where 0,0 represents the center of the circle).
cos → const double Function(num radians)
Computes and returns the cosine of the specified angle in radians.
E → const double
A mathematical constant for the base of natural logarithms, expressed as e.
exp → const double Function(num x)
Returns the value of the base of the natural logarithm (e), to the power of the exponent specified in the parameter x.
LN2 → const double
A mathematical constant for the natural logarithm of 2, expressed as loge2, with an approximate value of 0.6931471805599453.
LN10 → const double
A mathematical constant for the natural logarithm of 10, expressed as loge10, with an approximate value of 2.302585092994046.
log → const double Function(num x)
Returns the natural logarithm of the parameter x.
LOG2E → const double
A mathematical constant for the base-2 logarithm of the constant e, expressed as log2e, with an approximate value of 1.442695040888963387.
LOG10E → const double
A mathematical constant for the base-10 logarithm of the constant e (Math.E), expressed as log10e, with an approximate value of 0.4342944819032518.
max → const T Function<T extends num>(T a, T b)
Evaluates a and b and returns the largest value.
min → const T Function<T extends num>(T a, T b)
Evaluates a and b and returns the smallest value.
PI → const double
A mathematical constant for the ratio of the circumference of a circle to its diameter, expressed as pi, with a value of ~3.141592653589793.
PI1_2 → const double
Shortcut for Math.PI/2, represents an angle of 90 degrees in radians.
PI_2 → const double
Shortcut for Math.PI * 2, represents a 360 degree angle
pow → const num Function(num x, num exponent)
Computes and returns x to the power of exponent.
sin → const double Function(num radians)
Computes and returns the sine of the specified angle in radians.
sqrt → const double Function(num x)
Computes and returns the square root of 'x'.
SQRT1_2 → const double
A mathematical constant for the square root of one-half, with an approximate value of 0.7071067811865476.
SQRT2 → const double
A mathematical constant for the square root of 2, with an approximate value of 1.4142135623730951.
tan → const double Function(num radians)
Computes and returns the tangent of the specified angle. Shortcut of math.tan