Dart API Referencedart:coreint

int abstract class

Representation of Dart integers containing integer specific operations and specialization of operations inherited from num.

Integers can be arbitrarily large in Dart.

Note however, that when compiling to JavaScript, integers are implemented as JavaScript numbers. When compiling to JavaScript, integers are therefore restricted to 53 significant bits because all JavaScript numbers are double-precision floating point values. The behavior of the operators and methods in the int class therefore sometimes differs between the Dart VM and Dart code compiled to JavaScript.

abstract class int extends num {
 /** The bit-wise and operator. */
 int operator &(int other);

 /** The bit-wise or operator. */
 int operator |(int other);

 /** The bit-wise xor operator. */
 int operator ^(int other);

 /** The bit-wise negate operator. */
 int operator ~();

 /** The left shift operator. */
 int operator <<(int shiftAmount);

 /** The right shift operator. */
 int operator >>(int shiftAmount);

 /** Returns true if and only if this integer is even. */
 bool get isEven;

 /** Returns true if and only if this integer is odd. */
 bool get isOdd;

 /** Negate operator. Negating an integer produces an integer. */
 int operator -();

 /** Returns the absolute value of this integer. */
 int abs();

 /** Returns `this`. */
 int round();

 /** Returns `this`. */
 int floor();

 /** Returns [this]. */
 int ceil();

 /** Returns [this]. */
 int truncate();

 /** Returns `this.toDouble()`. */
 double roundToDouble();

 /** Returns `this.toDouble()`. */
 double floorToDouble();

 /** Returns `this.toDouble()`. */
 double ceilToDouble();

 /** Returns `this.toDouble()`. */
 double truncateToDouble();

 /**
  * Returns a representation of this [int] value.
  *
  * It should always be the case that if [:i:] is an [int] value,
  * then [:i == int.parse(i.toString()):].
  */
 String toString();

 /**
  * Converts [this] to a string representation in the given [radix].
  *
  * In the string representation, lower-case letters are used for digits above
  * '9'.
  *
  * The [radix] argument must be an integer in the range 2 to 36.
  */
 String toRadixString(int radix);

 /**
  * Parse [source] as an integer literal and return its value.
  *
  * The [radix] must be in the range 2..36. The digits used are
  * first the decimal digits 0..9, and then the letters 'a'..'z'.
  * Accepts capital letters as well.
  *
  * If no [radix] is given then it defaults to 16 if the string starts
  * with "0x", "-0x" or "+0x" and 10 otherwise.
  *
  * The [source] must be a non-empty sequence of base-[radix] digits,
  * optionally prefixed with a minus or plus sign ('-' or '+').
  *
  * It must always be the case for an int [:n:] and radix [:r:] that
  * [:n == parseRadix(n.toRadixString(r), r):].
  *
  * If the [source] is not a valid integer literal, optionally prefixed by a
  * sign, the [onError] is called with the [source] as argument, and its return
  * value is used instead. If no [onError] is provided, a [FormatException]
  * is thrown.
  */
 external static int parse(String source,
                           { int radix,
                             int onError(String source) });
}

Extends

num > int

Subclasses

JSInt

Static Methods

int parse(String source, {int radix, int onError(String source)}) #

Parse source as an integer literal and return its value.

The radix must be in the range 2..36. The digits used are first the decimal digits 0..9, and then the letters 'a'..'z'. Accepts capital letters as well.

If no radix is given then it defaults to 16 if the string starts with "0x", "-0x" or "+0x" and 10 otherwise.

The source must be a non-empty sequence of base- radix digits, optionally prefixed with a minus or plus sign ('-' or '+').

It must always be the case for an int n and radix r that n == parseRadix(n.toRadixString(r), r).

If the source is not a valid integer literal, optionally prefixed by a sign, the onError is called with the source as argument, and its return value is used instead. If no onError is provided, a FormatException is thrown.

external static int parse(String source,
                         { int radix,
                           int onError(String source) });

Properties

final bool isEven #

Returns true if and only if this integer is even.

bool get isEven;

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;

final bool isOdd #

Returns true if and only if this integer is odd.

bool get isOdd;

Operators

abstract num operator +(num other) #

inherited from num

Addition operator.

abstract int operator -() #

Negate operator. Negating an integer produces an integer.

abstract num operator -(num other) #

inherited from num

Subtraction operator.

abstract num operator *(num other) #

inherited from num

Multiplication operator.

abstract double operator /(num other) #

inherited from num

Division operator.

abstract int operator ~/(num other) #

inherited from num

Truncating division operator.

If either operand is a double then the result of the truncating division a ~/ b is equivalent to (a / b).truncate().toInt().

If both operands are ints then a ~/ b performs the truncating integer division.

abstract num operator %(num other) #

inherited from num

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.

abstract int operator &(int other) #

The bit-wise and operator.

abstract int operator |(int other) #

The bit-wise or operator.

abstract int operator ^(int other) #

The bit-wise xor operator.

abstract int operator ~() #

The bit-wise negate operator.

abstract int operator <<(int shiftAmount) #

The left shift operator.

abstract int operator >>(int shiftAmount) #

The right shift operator.

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 int abs() #

Returns the absolute value of this integer.

abstract int ceil() #

Returns this.

abstract double ceilToDouble() #

Returns this.toDouble().

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 this.

abstract double floorToDouble() #

Returns this.toDouble().

abstract num remainder(num other) #

inherited from num

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 this.

abstract double roundToDouble() #

Returns this.toDouble().

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 toRadixString(int radix) #

Converts this to a string representation in the given radix.

In the string representation, lower-case letters are used for digits above '9'.

The radix argument must be an integer in the range 2 to 36.

abstract String toString() #

Returns a representation of this int value.

It should always be the case that if i is an int value, then i == int.parse(i.toString()).

abstract String toStringAsExponential([int fractionDigits]) #

inherited from num

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) #

inherited from num

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) #

inherited from num

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 this.

abstract double truncateToDouble() #

Returns this.toDouble().