Skip to main content
i64 is a primitive signed integer type in Rust that occupies 64 bits (8 bytes) of memory. It represents whole numbers using two’s complement binary encoding, utilizing the most significant bit (MSB) as the sign bit to distinguish between positive and negative values.

Technical Specifications

  • Memory Size: 64 bits (8 bytes)
  • Encoding: Two’s complement
  • Minimum Value (i64::MIN): 263-2^{63} (-9,223,372,036,854,775,808)
  • Maximum Value (i64::MAX): 26312^{63} - 1 (9,223,372,036,854,775,807)

Syntax and Instantiation

Rust provides multiple ways to declare an i64 value, including explicit type annotations and literal suffixes. Visual separators (_) can be used to improve literal readability without affecting the compiled value.

Overflow and Underflow Handling

By default, Rust handles i64 arithmetic overflows differently based on the compilation profile:
  • Debug profile: Integer overflow triggers a thread panic.
  • Release profile: Integer overflow performs two’s complement wrapping.
To explicitly dictate overflow behavior regardless of the compilation profile, i64 provides dedicated standard library methods:

Type Casting

Conversion between i64 and other primitive numeric types is performed using the as keyword. Casting a larger integer type to i64 (e.g., i128 as i64) truncates the higher-order bits, while casting a smaller type (e.g., i32 as i64) performs sign extension to preserve the numeric value.

Trait Implementations

As a core primitive, i64 implements several fundamental traits, ensuring integration with Rust’s strict type system and standard library operations:
  • Memory/Concurrency: Copy, Clone, Send, Sync
  • Comparison: Eq, PartialEq, Ord, PartialOrd
  • Arithmetic: Add, Sub, Mul, Div, Rem, Neg (and their Assign variants)
  • Bitwise: BitAnd, BitOr, BitXor, Shl, Shr (and their Assign variants)
  • Formatting: Display, Debug, LowerHex, UpperHex, Octal, Binary
Tired of Poor Rust Skills? Fix That With Deep Grasping!Learn More