int class

An integer number.

The default implementation of int is 64-bit two's complement integers with operations that wrap to that range on overflow.

Note: When compiling to JavaScript, integers are restricted to values that can be represented exactly by double-precision floating point values. The available integer values include all integers between -2^53 and 2^53, and some integers with larger magnitude. That includes some integers larger than 2^63. The behavior of the operators and methods in the int class therefore sometimes differs between the Dart VM and Dart code compiled to JavaScript. For example, the bitwise operators truncate their operands to 32-bit integers when compiled to JavaScript.

Classes cannot extend, implement, or mix in int.

Inheritance

Constructors

int.fromEnvironment(String name, {int defaultValue = 0})
const
factory
Returns the integer value of the given environment declaration name. [...]

Properties

bitLengthint
read-only
Returns the minimum number of bits required to store this integer. [...]
hashCodeint
read-only, inherited
Returns a hash code for a numerical value. [...]
isEvenbool
read-only
Returns true if and only if this integer is even.
isFinitebool
read-only, inherited
Whether the number is finite. [...]
isInfinitebool
read-only, inherited
Whether the number is positive infinity or negative infinity.
isNaNbool
read-only, inherited
Whether the number is the double Not-a-Number value.
isNegativebool
read-only, inherited
Whether if the number is negative. [...]
isOddbool
read-only
Returns true if and only if this integer is odd.
runtimeTypeType
read-only, inherited
A representation of the runtime type of the object.
signint
read-only, override
Returns the sign of this integer. [...]

Methods

abs() → int
override
Returns the absolute value of this integer. [...]
ceil() → int
override
Returns this.
ceilToDouble() → double
override
Returns this.toDouble().
clamp(num lowerLimit, num upperLimit) → num
inherited
Returns this num clamped to be in the range lowerLimit-upperLimit. [...]
compareTo(num other) → int
inherited
Compares this to other. [...]
floor() → int
override
Returns this.
floorToDouble() → double
override
Returns this.toDouble().
gcd(int other) → int
Returns the greatest common divisor of this integer and other. [...]
modInverse(int modulus) → int
Returns the modular multiplicative inverse of this integer modulo modulus. [...]
modPow(int exponent, int modulus) → int
Returns this integer to the power of exponent modulo modulus. [...]
noSuchMethod(Invocation invocation) → dynamic
inherited
Invoked when a non-existent method or property is accessed. [...]
remainder(num other) → num
inherited
The remainder of the truncating division of this by other. [...]
round() → int
override
Returns this.
roundToDouble() → double
override
Returns this.toDouble().
toDouble() → double
inherited
This number as a double. [...]
toInt() → int
inherited
Truncates this num to an integer and returns the result as an int. [...]
toRadixString(int radix) → String
Converts this to a string representation in the given radix. [...]
toSigned(int width) → int
Returns the least significant width bits of this integer, extending the highest retained bit to the sign. This is the same as truncating the value to fit in width bits using an signed 2-s complement representation. The returned value has the same bit value in all positions higher than width. [...]
toString() → String
override
Returns a string representation of this integer. [...]
toStringAsExponential([int? fractionDigits]) → String
inherited
An exponential string-representation of this number. [...]
toStringAsFixed(int fractionDigits) → String
inherited
A decimal-point string-representation of this number. [...]
toStringAsPrecision(int precision) → String
inherited
A string representation with precision significant digits. [...]
toUnsigned(int width) → int
Returns the least significant width bits of this integer as a non-negative number (i.e. unsigned representation). The returned value has zeros in all bit positions higher than width. [...]
truncate() → int
override
Returns this.
truncateToDouble() → double
override
Returns this.toDouble().

Operators

operator %(num other) → num
inherited
Euclidean modulo of this number by other. [...]
operator &(int other) → int
Bit-wise and operator. [...]
operator *(num other) → num
inherited
Multiplies this number by other. [...]
operator +(num other) → num
inherited
Adds other to this number. [...]
operator -(num other) → num
inherited
Subtracts other from this number. [...]
operator /(num other) → double
inherited
Divides this number by other.
operator <(num other) → bool
inherited
Whether other is numerically smaller than this number. [...]
operator <<(int shiftAmount) → int
Shift the bits of this integer to the left by shiftAmount. [...]
operator <=(num other) → bool
inherited
Whether other is numerically smaller than or equal to this number. [...]
operator ==(Object other) → bool
inherited
Test whether this value is numerically equal to other. [...]
operator >(num other) → bool
inherited
Whether other is numerically greater than this number. [...]
operator >=(num other) → bool
inherited
Whether other is numerically greater than or equal to this number. [...]
operator >>(int shiftAmount) → int
Shift the bits of this integer to the right by shiftAmount. [...]
operator ^(int other) → int
Bit-wise exclusive-or operator. [...]
operator unary-() → int
override
Return the negative value of this integer. [...]
operator |(int other) → int
Bit-wise or operator. [...]
operator ~() → int
The bit-wise negate operator. [...]
operator ~/(num other) → int
inherited
Truncating division operator. [...]

Static Methods

parse(String source, {int? radix, int onError(String source)}) → int
override
Parse source as a, possibly signed, integer literal and return its value. [...]
tryParse(String source, {int? radix}) → int?
override
Parse source as a, possibly signed, integer literal. [...]

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-core/int-class.html