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 the same format as double literals:
* [: ['+'|'-'] [digit* '.'] digit+ [('e'|'E') ['+'|'-'] digit+] :]
*
* Also recognizes "NaN", "Infinity" and "-Infinity" as inputs and
* returns the corresponding double value.
*
* If the [soure] 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.
*/
external static double parse(String source,
[double handleError(String source)]);
}
Extends
num > double
Subclasses
Static Properties
Static Methods
double parse(String source, [double handleError(String source)]) #
Parse source as an double literal and return its value.
Accepts the same format as double literals:
['+'|'-'] [digit* '.'] digit+ [('e'|'E') ['+'|'-'] digit+]
Also recognizes "NaN", "Infinity" and "-Infinity" as inputs and returns the corresponding double value.
If the soure 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.
external static double parse(String source,
[double handleError(String source)]);
Properties
Operators
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|.
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.
Methods
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) #
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) #
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) #
Return 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.
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 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]) #
Converts this to 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) #
Converts this to a 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) #
Converts this to 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.