- i8
- u8
- i32
- i64
Rust numerical types
- By default integer numbers are stored in i32 that has a range of -2147483648..=2147483647.
- By default floating point numbers are stored in f64.
- We can explicitely put numbers in different types.
- In Python a small integers takes up 28 bytes. Size of integers in Python.
examples/numbers/number-types/src/main.rs
#![allow(clippy::approx_constant)] fn main() { let number = 139871; println!("{number}"); let number: i8 = 100; println!("{number}"); let number: u8 = 255; println!("{number}"); let number = 300_000_000; println!("{number}"); let number: i64 = 3_000_000_000; println!("{number}"); let number = 3.14; println!("{number}"); let number: f32 = 3.14; println!("{number}"); }
139871 100 255 300000000 3000000000 3.14 3.14