int is a primitive numeric data type representing a non-fractional value, implemented as a subtype of num. It serves as the standard representation for integers within the Dart type system.
Platform Implementation
The internal representation ofint is platform-dependent:
- Dart VM (Native): Represents a strictly 64-bit two’s complement signed integer.
- Range:
-2^63to2^63 - 1. - Overflow: Arithmetic operations that exceed this range wrap around.
- Range:
- Dart Web (JavaScript): Maps to a JavaScript Number (IEEE 754 double-precision floating-point).
- Range: The safe integer precision range is
-(2^53 - 1)to2^53 - 1. Values exceeding this range may suffer precision loss due to the limitations of the floating-point mantissa. - Bitwise Operations: Operations are truncated to 32 bits to align with JavaScript bitwise behavior.
- Range: The safe integer precision range is
Syntax and Literals
Dart supports integer literals in decimal and hexadecimal formats.1e3) are strictly typed as double, even if the resulting value is a whole number. Assigning a scientific notation literal to an int results in a compile-time error.
Type Safety and Conversion
Dart is strongly typed and does not support implicit widening (coercion) from anint variable to a double. While integer literals can be assigned to double variables (inferred as doubles), typed int variables require explicit casting methods.
- No Implicit Widening: Assigning an
inttyped variable to adoubleresults in a compile-time error. - Division: The standard division operator
/always returns adouble, even if the operands are integers and the result is a whole number. - Integer Division: The truncating division operator
~/returns anint.
Bitwise Operations
Theint class supports standard bitwise manipulation. On the web, these operations implicitly truncate the operand to 32 bits.
Key Properties
bitLength: Returns the minimum number of bits required to store the integer.isEven/isOdd: Boolean properties indicating parity.sign: Returns -1, 0, or 1 depending on the sign of the integer.
Comparison with BigInt
For integers exceeding the 64-bit range (native) or the 53-bit safe precision range (web), Dart provides theBigInt class. While int is optimized for performance and maps to CPU registers or JS primitives, BigInt allows for arbitrary precision at the cost of memory and processing speed.
Master Dart with Deep Grasping Methodology!Learn More





