Number class abstract
The abstract base class for all Number types.
- Implemented types
- Implementers
Constructors
- Number()
- The default constructor.
- Number.constant()
-
Supports const constructors in concrete classes.
const
-
Number.fromMap(Map<
String, dynamic> ? m) -
Detect the type of Number by inspecting map contents and create it.
Recognized formats are:
{'i': int value}
{'d': double value}
{'pd': arbitrary precision string}
{'real': {i or d map}, 'imag': {i or d map}}
{'imag': {i or d map}}
factory
Properties
- hashCode → int
-
The hash codes for two Numbers will be equal when the represented values are equal,
even if the Number subtypes are different.
no setteroverride
- isFinite → bool
-
Whether this Number represents a finite value.
no setter
- isInfinite → bool
-
Whether this Number represents infinity.
no setter
- isInteger → bool
-
True if the Number represents an integer value.
Note that the Number does not have to be of type
Integer for this to be true.
no setter
- isNaN → bool
-
Whether this Number represents a value .
no setter
- isNegative → bool
-
Whether this number is less than zero.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sign → num
-
Returns minus one, zero or plus one depending on the sign and numerical value of the number.
Returns minus one if the number is less than zero, plus one if the number is greater than zero,
and zero if the number is equal to zero. Returns NaN if the number is NaN.
Returns an
int
if this Number's value is an integer, adouble
otherwise.no setter
Methods
-
abs(
) → Number - Returns the absolute value of this Number.
-
ceil(
) → Number - Returns the least Number having integer components no smaller than this Number.
-
clamp(
dynamic lowerLimit, dynamic upperLimit) → Number -
Returns this num clamped to be in the range lowerLimit-upperLimit.
The comparison is done using compareTo and therefore takes -0.0 into account.
This also implies that double.NAN is treated as the maximal double value.
lowerLimit
andupperLimit
are expected to benum
or `Number' objects. -
compareTo(
dynamic n2) → int -
Compares this Number to another Number by comparing values.
n2
is expected to be a num or Number. If it is not it will be considered to have a value of 0.override -
floor(
) → Number - Returns the greatest Number with an integer value no greater than this Number. If this is not finite (NaN or infinity), throws an UnsupportedError.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reciprocal(
) → Number - Returns the Number that is the reciprocal of this Number. This Number is unaffected.
-
remainder(
dynamic divisor) → Number -
Returns the remainder of the truncating division of this Number by
divisor
. The result r of this operation satisfies: this == (this ~/ other) * other + r. As a consequence the remainder r has the same sign as the operator /(divisor). -
round(
) → Number - Returns the integer Number closest to this Number. 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.
-
toDouble(
) → double -
Converts this Number to a
dart:core double
. -
toInt(
) → int -
Converts this Number to a
dart:core int
. -
toJson(
) → Map< String, dynamic> - Subclasses must support dart:json for stringify.
-
toString(
) → String -
A string representation of this object.
inherited
-
truncate(
) → Number - Returns a truncated value.
Operators
-
operator %(
dynamic divisor) → Number -
Returns the remainder after division of this Number by
divisor
(a Number or num). -
operator *(
dynamic multiplicand) → Number -
Returns the product of this Number and the
multiplicand
(a Number or num). This Number is unaffected. -
operator +(
dynamic addend) → Number - Returns the sum of this Number and a Number or num. This Number is unaffected.
-
operator -(
dynamic subtrahend) → Number -
Returns the difference of this Number and the
subtrahend
(a Number or num). This Number is unaffected. -
operator /(
dynamic divisor) → Number -
Returns the quotient of this Number divided by the
divisor
(a Number or num). This Number is unaffected. -
operator <(
dynamic obj) → bool - Returns whether the value of this Number is less than the value of obj (a Number or num).
-
operator <=(
dynamic obj) → bool - Returns whether the value of this Number is less than or equal to the value of obj (a Number or num).
-
operator ==(
Object obj) → bool -
Two Numbers will be equal when the represented values are equal,
even if the Number subtypes are different.
override
-
operator >(
dynamic obj) → bool - Returns whether the value of this Number is greater than the value of obj (a Number or num).
-
operator >=(
dynamic obj) → bool - Returns whether the value of this Number is greater than or equal to the value of obj (a Number or num).
-
operator ^(
dynamic exponent) → Number -
Returns this Number raised to the power of
exponent
(a Number or num). This Number is unaffected. -
operator unary-(
) → Number - Returns the negative of this Number. This Number is unaffected.
-
operator ~/(
dynamic divisor) → Number -
Returns the quotient of this Number divided by the
divisor
(a Number or num) truncated to an Integer. This Number is unaffected.
Static Methods
-
simplifyType(
Number n) → Number -
Returns the Number equivalent to
n
having the simplest type that can represent the value (in order): Integer, Double, Imaginary, or Complex. Ifn
is already the most simple type possible, then it will be returned directly. Precise Numbers always remain Precise.