dart.math


Top-Level Variables
E: double
LN10: double
LN2: double
LOG10E: double
LOG2E: double
PI: double
SQRT1_2: double
SQRT2: double
Functions
acos(num x): double
asin(num x): double
atan(num x): double
atan2(num a, num b): double
cos(num x): double
exp(num x): double
log(num x): double
max(num a, num b): num
min(num a, num b): num
pow(num x, num exponent): num
sin(num x): double
sqrt(num x): double
tan(num x): double
Classes
Random

Mathematical constants and functions, plus a random number generator.

Top-Level Variables

static const double E = 2.718281828459045

Base of the natural logarithms.

Typically written as "e".

static const double LN10 = 2.302585092994046

Natural logarithm of 10.

static const double LN2 = 0.6931471805599453

Natural logarithm of 2.

static const double LOG10E = 0.4342944819032518

Base-10 logarithm of E.

static const double LOG2E = 1.4426950408889634

Base-2 logarithm of E.

static const double PI = 3.141592653589793

The PI constant.

static const double SQRT1_2 = 0.7071067811865476

Square root of 1/2.

static const double SQRT2 = 1.4142135623730951

Square root of 2.

Functions

static double acos(num x)

Converts x to a double and returns the arc cosine of the value.

Returns a value in the range -PI..PI, or NaN if x is outside the range -1..1.

static double asin(num x)

Converts x to a double and returns the arc sine of the value. Returns a value in the range -PI..PI, or NaN if x is outside the range -1..1.

static double atan(num x)

Converts x to a dobule and returns the arc tangent of the vlaue. Returns a value in the range -PI/2..PI/2, or NaN if x is NaN.

static double atan2(num a, num b)

A variant of atan.

Converts both arguments to doubles.

Returns the angle between the positive x-axis and the vector (b,a). The result, in radians, is in the range -PI..PI.

If b is positive, this is the same as atan(b/a).

The result is negative when a is negative (including when a is the double -0.0).

If a is equal to zero, the vector (b,a) is considered parallel to the x-axis, even if b is also equal to zero. The sign of b determines the direction of the vector along the x-axis.

Returns NaN if either argument is NaN.

static double cos(num x)

Converts x to a double and returns the cosine of the value.

If x is not a finite number, the result is NaN.

static double exp(num x)

Converts x to a double and returns the natural exponent, E, to the power x. Returns NaN if x is NaN.

static double log(num x)

Converts x to a double and returns the natural logarithm of the value. Returns negative infinity if x is equal to zero. Returns NaN if x is NaN or less than zero.

static num max(num a, num b)

Returns the larger of two numbers.

Returns NaN if either argument is NaN. The larger of -0.0 and 0.0 is 0.0. If the arguments are otherwise equal (including int and doubles with the same mathematical value) then it is unspecified which of the two arguments is returned.

static num min(num a, num b)

Returns the lesser of two numbers.

Returns NaN if either argument is NaN. The lesser of -0.0 and 0.0 is -0.0. If the arguments are otherwise equal (including int and doubles with the same mathematical value) then it is unspecified which of the two arguments is returned.

static num pow(num x, num exponent)

Returns x to the power of exponent.

If x is an int and exponent is a non-negative int, the result is an int, otherwise both arguments are converted to doubles first, and the result is a double.

For integers, the power is always equal to the mathematical result of x to the power exponent, only limited by the available memory.

For doubles, pow(x, y) handles edge cases as follows:

- if y is zero (0.0 or -0.0), the result is always 1.0. - if x is 1.0, the result is always 1.0. - otherwise, if either x or y is NaN then the result is NaN. - if x is negative (but not -0.0) and y is a finite non-integer, the result is NaN. - if x is Infinity and y is negative, the result is 0.0. - if x is Infinity and y is positive, the result is Infinity. - if x is 0.0 and y is negative, the result is Infinity. - if x is 0.0 and y is positive, the result is 0.0. - if x is -Infinity or -0.0 and y is an odd integer, then the result is -pow(-x ,y). - if x is -Infinity or -0.0 and y is not an odd integer, then the result is the same as pow(-x , y). - if y is Infinity and the absolute value of x is less than 1, the result is 0.0. - if y is Infinity and x is -1, the result is 1.0. - if y is Infinity and the absolute value of x is greater than 1, the result is Infinity. - if y is -Infinity, the result is 1/pow(x, Infinity).

This corresponds to the pow function defined in the IEEE Standard 754-2008.

Notice that an int result cannot overflow, but a double result might be double.INFINITY.

static double sin(num x)

Converts x to a double and returns the sine of the value.

If x is not a finite number, the result is NaN.

static double sqrt(num x)

Converts x to a double and returns the positive square root of the value.

Returns -0.0 if x is -0.0, and NaN if x is otherwise negative or NaN.

static double tan(num x)

Converts x to a double and returns the tangent of the value.

The tangent function is equivalent to sin(x)/cos(x) and may be infinite (positive or negative) when cos(x) is equal to zero. If x is not a finite number, the result is NaN.


Abstract class Random

Constructors
Random(int seed)
Methods
nextBool(): bool
nextDouble(): double
nextInt(int max): int

A generator of random bool, int, or double values.

The default implementation supplies a stream of pseudo-random bits that are not suitable for cryptographic purposes.

Constructors

factory Random(int seed)

Creates a random-number generator. The optional parameter seed is used to initialize the internal state of the generator. The implementation of the random stream can change between releases of the library.

Implementation note: The default implementation uses up to 64-bits of seed.

Methods

bool nextBool()

Generates a random boolean value.

double nextDouble()

Generates a positive random floating point value uniformly distributed on the range from 0.0, inclusive, to 1.0, exclusive.

int nextInt(int max)

Generates a positive random integer uniformly distributed on the range from 0, inclusive, to max, exclusive.

Implementation note: The default implementation supports max values between 1 and ((1<<32) - 1) inclusive.