Dart API Referencedart:coredouble

double abstract class

Representation of Dart doubles containing double specific constants and operations and specializations of operations inherited from num.

The double type is contagious. Operations on doubles return double results.

abstract class double extends num {
 static const double NAN = 0.0 / 0.0;
 static const double INFINITY = 1.0 / 0.0;
 static const double NEGATIVE_INFINITY = -INFINITY;
 static const double MIN_POSITIVE = 5e-324;
 static const double MAX_FINITE = 1.7976931348623157e+308;

 double remainder(num other);

 /** Addition operator. */
 double operator +(num other);

 /** Subtraction operator. */
 double operator -(num other);

 /** Multiplication operator. */
 double operator *(num other);

 double operator %(num other);

 /** Division operator. */
 double operator /(num other);

 /**
  * Truncating division operator.
  *
  * The result of the truncating division [:a ~/ b:] is equivalent to
  * [:(a / b).truncate():].
  */
 int operator ~/(num other);

 /** Negate operator. */
 double operator -();

 /** Returns the absolute value of this [double]. */
 double abs();

 /**
  * Returns the integer closest to `this`.
  *
  * Rounds away from zero when there is no closest integer:
  *  [:(3.5).round() == 4:] and [:(-3.5).round() == -4:].
  *
  * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
  */
 int round();

 /**
  * Returns the greatest integer no greater than `this`.
  *
  * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
  */
 int floor();

 /**
  * Returns the least integer no smaller than `this`.
  *
  * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
  */
 int ceil();

 /**
  * Returns the integer obtained by discarding any fractional
  * digits from `this`.
  *
  * If `this` is not finite (`NaN` or infinity), throws an [UnsupportedError].
  */
 int truncate();

 /**
  * Returns the integer value, as a double, closest to `this`.
  *
  * Rounds away from zero when there is no closest integer:
  *  [:(3.5).round() == 4:] and [:(-3.5).round() == -4:].
  */
 double roundToDouble();

 /**
  * Returns the greatest integer value no greater than `this`.
  *
  * The result is a double.
  */
 double floorToDouble();

 /**
  * Returns the least integer value no smaller than `this`.
  *
  * The result is a double.
  */
 double ceilToDouble();

 /**
  * Returns the integer obtained by discarding any fractional
  * digits from `this`.
  *
  * The result is a double.
  */
 double truncateToDouble();

 /**
  * Provide a representation of this [double] value.
  *
  * The representation is a number literal such that the closest double value
  * to the representation's mathematical value is this [double].
  *
  * Returns "NaN" for the Not-a-Number value.
  * Returns "Infinity" and "-Infinity" for positive and negative Infinity.
  * Returns "-0.0" for negative zero.
  *
  * It should always be the case that if [:d:] is a [double], then
  * [:d == double.parse(d.toString()):].
  */
 String toString();

 /**
  * Parse [source] as an double literal and return its value.
  *
  * Accepts an optional sign (`+` or `-`) followed by either the characters
  * "Infinity", the characters "NaN" or a floating-point representation.
  * A floating-point representation is composed of a mantissa and an optional
  * exponent part. The mantissa is either a decimal point (`.`) followed by a
  * sequence of (decimal) digits, or a sequence of digits
  * optionally followed by a decimal point and optionally more digits. The
  * (optional) exponent part consists of the character "e" or "E", an optional
  * sign, and one or more digits.
  *
  * The input string is trimmed (see [String.trim]) before conversion.
  *
  * If the [source] is not a valid double literal, the [handleError]
  * is called with the [source] as argument, and its return value is
  * used instead. If no handleError is provided, a [FormatException]
  * is thrown.
  *
  * Examples of accepted strings:
  *
  *     "3.14"
  *     "  3.14 \xA0"
  *     "0."
  *     ".0"
  *     "-1.e3"
  *     "1234E+7"
  *     "+.12e-9"
  *     "-NaN"
  */
 external static double parse(String source,
                              [double handleError(String source)]);
}

Extends

num > double

Subclasses

JSDouble, JSInt

Static Properties

const double INFINITY #

static const double INFINITY = 1.0 / 0.0

const double MAX_FINITE #

static const double MAX_FINITE = 1.7976931348623157e+308

const double MIN_POSITIVE #

static const double MIN_POSITIVE = 5e-324

const double NAN #

static const double NAN = 0.0 / 0.0

const double NEGATIVE_INFINITY #

static const double NEGATIVE_INFINITY = -INFINITY

Static Methods

double parse(String source, [double handleError(String source)]) #

Parse source as an double literal and return its value.

Accepts an optional sign (+ or -) followed by either the characters "Infinity", the characters "NaN" or a floating-point representation. A floating-point representation is composed of a mantissa and an optional exponent part. The mantissa is either a decimal point (.) followed by a sequence of (decimal) digits, or a sequence of digits optionally followed by a decimal point and optionally more digits. The (optional) exponent part consists of the character "e" or "E", an optional sign, and one or more digits.

The input string is trimmed (see String.trim) before conversion.

If the source is not a valid double literal, the handleError is called with the source as argument, and its return value is used instead. If no handleError is provided, a FormatException is thrown.

Examples of accepted strings:

"3.14"
"  3.14 \xA0"
"0."
".0"
"-1.e3"
"1234E+7"
"+.12e-9"
"-NaN"
external static double parse(String source,
                            [double handleError(String source)]);

Properties

final bool isInfinite #

inherited from num
bool get isInfinite;

final bool isNaN #

inherited from num
bool get isNaN;

final bool isNegative #

inherited from num
bool get isNegative;

Operators

abstract double operator +(num other) #

Addition operator.

abstract double operator -() #

Negate operator.

abstract double operator -(num other) #

Subtraction operator.

abstract double operator *(num other) #

Multiplication operator.

abstract double operator /(num other) #

Division operator.

abstract int operator ~/(num other) #

Truncating division operator.

The result of the truncating division a ~/ b is equivalent to (a / b).truncate().

abstract double operator %(num other) #

Euclidean modulo operator.

Returns the remainder of the euclidean division. The euclidean division of two integers a and b yields two integers q and r such that a == b*q + r and 0 <= r < a.abs().

The euclidean division is only defined for integers, but can be easily extended to work with doubles. In that case r may have a non-integer value, but it still verifies 0 <= r < |a|.

The sign of the returned value r is always positive.

See remainder for the remainder of the truncating division.

docs inherited from num

abstract bool operator <(num other) #

inherited from num

Relational less than operator.

abstract bool operator <=(num other) #

inherited from num

Relational less than or equal operator.

abstract bool operator >(num other) #

inherited from num

Relational greater than operator.

abstract bool operator >=(num other) #

inherited from num

Relational greater than or equal operator.

Methods

abstract double abs() #

Returns the absolute value of this double.

abstract int ceil() #

Returns the least integer no smaller than this.

If this is not finite (NaN or infinity), throws an UnsupportedError.

abstract double ceilToDouble() #

Returns the least integer value no smaller than this.

The result is a double.

abstract num clamp(num lowerLimit, num upperLimit) #

inherited from num

Clamps this to be in the range lowerLimit- upperLimit. The comparison is done using compareTo and therefore takes -0.0 into account. It also implies that double.NAN is treated as the maximal double value.

abstract int compareTo(T other) #

inherited from Comparable

Compares this object to another Comparable

Returns a value like a Comparator when comparing this to other.

May throw an ArgumentError if other is of a type that is not comparable to this.

abstract int floor() #

Returns the greatest integer no greater than this.

If this is not finite (NaN or infinity), throws an UnsupportedError.

abstract double floorToDouble() #

Returns the greatest integer value no greater than this.

The result is a double.

abstract double remainder(num other) #

Returns the remainder of the truncating division of this by other.

The result r of this operation satisfies: this == this ~/ other + r. As a consequence the remainder r has the same sign as the dividend this.

docs inherited from num

abstract int round() #

Returns the integer closest to this.

Rounds away from zero when there is no closest integer: (3.5).round() == 4 and (-3.5).round() == -4.

If this is not finite (NaN or infinity), throws an UnsupportedError.

abstract double roundToDouble() #

Returns the integer value, as a double, closest to this.

Rounds away from zero when there is no closest integer: (3.5).round() == 4 and (-3.5).round() == -4.

abstract double toDouble() #

inherited from num

Return this num as a double.

If the number is not representable as a double, an approximation is returned. For numerically large integers, the approximation may be infinite.

abstract int toInt() #

inherited from num

Truncates this num to an integer and returns the result as an int.

abstract String toString() #

Provide a representation of this double value.

The representation is a number literal such that the closest double value to the representation's mathematical value is this double.

Returns "NaN" for the Not-a-Number value. Returns "Infinity" and "-Infinity" for positive and negative Infinity. Returns "-0.0" for negative zero.

It should always be the case that if d is a double, then d == double.parse(d.toString()).

abstract String toStringAsExponential([int fractionDigits]) #

inherited from num

Converts this to a double and then gives a string in decimal exponential notation with fractionDigits digits after the decimal point.

If fractionDigits is given then it must be an integer satisfying: 0 <= fractionDigits <= 20. Without the parameter the returned string uses the shortest number of digits that accurately represent this.

abstract String toStringAsFixed(int fractionDigits) #

inherited from num

Converts this to a double and then gives string representation with fractionDigits digits after the decimal point.

The parameter fractionDigits must be an integer satisfying: 0 <= fractionDigits <= 20.

abstract String toStringAsPrecision(int precision) #

inherited from num

Converts this to a double and gives a string representation with precision significant digits.

The parameter precision must be an integer satisfying: 1 <= precision <= 21.

abstract int truncate() #

Returns the integer obtained by discarding any fractional digits from this.

If this is not finite (NaN or infinity), throws an UnsupportedError.

abstract double truncateToDouble() #

Returns the integer obtained by discarding any fractional digits from this.

The result is a double.