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();

  /** For integers the round method is the identify function. */
  int round();

  /** For integers the floor method is the identify function. */
  int floor();

  /** For integers the ceil method is the identify function. */
  int ceil();

  /** For integers the truncate method is the identify function. */
  int truncate();

  /**
   * 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();

  /**
   * Parse [source] as an integer literal and return its value.
   *
   * Accepts "0x" prefix for hexadecimal numbers, otherwise defaults
   * to base-10.
   *
   * Throws a [FormatException] if [source] is not a valid integer literal.
   */
  external static int parse(String source);
}

Extends

num > int

Static Methods

int parse(String source) #

Parse source as an integer literal and return its value.

Accepts "0x" prefix for hexadecimal numbers, otherwise defaults to base-10.

Throws a FormatException if source is not a valid integer literal.

external static int parse(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

num operator +(num other) #

inherited from num

Addition operator.

num operator +(num other);

int operator -() #

Negate operator. Negating an integer produces an integer.

int operator -();

num operator -(num other) #

inherited from num

Subtraction operator.

num operator -(num other);

num operator *(num other) #

inherited from num

Multiplication operator.

num operator *(num other);

double operator /(num other) #

inherited from num

Division operator.

double operator /(num other);

num operator ~/(num other) #

inherited from num

Truncating division operator.

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

num operator ~/(num other);

num operator %(num other) #

inherited from num

Euclidean modulo operator.

num operator %(num other);

int operator &(int other) #

The bit-wise and operator.

int operator &(int other);

int operator |(int other) #

The bit-wise or operator.

int operator |(int other);

int operator ^(int other) #

The bit-wise xor operator.

int operator ^(int other);

int operator ~() #

The bit-wise negate operator.

int operator ~();

int operator <<(int shiftAmount) #

The left shift operator.

int operator <<(int shiftAmount);

int operator >>(int shiftAmount) #

The right shift operator.

int operator >>(int shiftAmount);

bool operator <(num other) #

inherited from num

Relational less than operator.

bool operator <(num other);

bool operator <=(num other) #

inherited from num

Relational less than or equal operator.

bool operator <=(num other);

bool operator >(num other) #

inherited from num

Relational greater than operator.

bool operator >(num other);

bool operator >=(num other) #

inherited from num

Relational greater than or equal operator.

bool operator >=(num other);

Methods

int abs() #

Returns the absolute value of this integer.

int abs();

int ceil() #

For integers the ceil method is the identify function.

int ceil();

abstract int compareTo(Comparable 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.

int floor() #

For integers the floor method is the identify function.

int floor();

num remainder(num other) #

inherited from num

Return the remainder from dividing this num by other.

num remainder(num other);

int round() #

For integers the round method is the identify function.

int round();

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.

double toDouble();

int toInt() #

inherited from num

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

int toInt();

String toRadixString(int radix) #

inherited from num

Converts a num to a string representation in the given radix.

The num in converted to an int using toInt. That int is then converted to a string representation with the given radix. In the string representation, lower-case letters are used for digits above '9'.

The radix argument must be an integer between 2 and 36.

String toRadixString(int radix);

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()).

String toString();

String toStringAsExponential(int fractionDigits) #

inherited from num

Converts a num to a string in decimal exponential notation with fractionDigits digits after the decimal point.

String toStringAsExponential(int fractionDigits);

String toStringAsFixed(int fractionDigits) #

inherited from num

Converts a num to a string representation with fractionDigits digits after the decimal point.

String toStringAsFixed(int fractionDigits);

String toStringAsPrecision(int precision) #

inherited from num

Converts a num to a string representation with precision significant digits.

String toStringAsPrecision(int precision);

int truncate() #

For integers the truncate method is the identify function.

int truncate();