Math Class
Note: This class is deprecated, and will be removed soon.
Please use the dart:math
library instead.
Static Methods
Code double atan2(num a, num b) #
Returns the arc tangent of a/ b with sign according to quadrant.
static double atan2(num a, num b) => MathNatives.atan2(a, b);
Code num max(num a, num b) #
Returns the maximum of two numbers. If either argument is NaN returns NaN.
The maximum of -0.0
and 0.0
is 0.0
. If both arguments are
equal (int and doubles with the same mathematical value are equal) then
it is unspecified which of the two arguments is returned.
static num max(num a, num b) { if (a is num) { // TODO(floitsch): merge this if into the previous one, once dart2js // correctly propagates types for logical ands. if (b is num) { if (a > b) return a; if (a < b) return b; if (b is double) { // Special case for NaN and -0.0. If one argument is NaN return NaN. // [max] must also distinguish between -0.0 and 0.0. if (a is double) { if (a == 0.0) { // a is either 0.0 or -0.0. b is either 0.0, -0.0, or NaN. // The following returns 0.0 if either a or b is 0.0, and it // returns NaN if b is NaN. return a + b; } } // Check for NaN. if (b.isNaN()) return b; return a; } // max(-0.0, 0) must return 0. if (b == 0 && a.isNegative()) return b; return a; } throw new IllegalArgumentException(b); } throw new IllegalArgumentException(a); }
Code num min(num a, num b) #
Returns the minimum of two numbers. If either argument is NaN returns NaN.
The minimum of -0.0
and 0.0
is -0.0
. If both arguments are
equal (int and doubles with the same mathematical value are equal) then
it is unspecified which of the two arguments is returned.
static num min(num a, num b) { if (a is num) { // TODO(floitsch): merge this if into the previous one, once dart2js // correctly propagates types for logical ands. if (b is num) { if (a > b) return b; if (a < b) return a; if (b is double) { // Special case for NaN and -0.0. If one argument is NaN return NaN. // [min] must also distinguish between -0.0 and 0.0. if (a is double) { if (a == 0.0) { // a is either 0.0 or -0.0. b is either 0.0, -0.0 or NaN. // The following returns -0.0 if either a or b is -0.0, and it // returns NaN if b is NaN. return (a + b) * a * b; } } // Check for NaN and b == -0.0. if (a == 0 && b.isNegative() || b.isNaN()) return b; return a; } return a; } throw new IllegalArgumentException(b); } throw new IllegalArgumentException(a); }
Code double parseDouble(String str) #
Parses a String representation of a double, and returns a double. Throws a BadNumberFormatException if str cannot be parsed as a double.
static double parseDouble(String str) => MathNatives.parseDouble(str);
Code int parseInt(String str) #
Parses a String representation of an int, and returns an int. Throws a BadNumberFormatException if str cannot be parsed as an int.
static int parseInt(String str) => MathNatives.parseInt(str);
Code num pow(num x, num exponent) #
If the exponent is an integer the result is of the same type as x. Otherwise it is a double.
static num pow(num x, num exponent) => MathNatives.pow(x, exponent);
Code double random() #
Returns a random double greater than or equal to 0.0 and less than 1.0.
static double random() => MathNatives.random();