Primitive Types
Integer Types
Signed Integers
| Type | Size | Min | Max |
|---|---|---|---|
i8 | 8-bit | -128 | 127 |
i16 | 16-bit | -32,768 | 32,767 |
i32 | 32-bit | -2,147,483,648 | 2,147,483,647 |
i64 | 64-bit | -9.2 * 10^18 | 9.2 * 10^18 |
isize | pointer-sized | Platform dependent | Platform dependent |
Unsigned Integers
| Type | Size | Min | Max |
|---|---|---|---|
u8 | 8-bit | 0 | 255 |
u16 | 16-bit | 0 | 65,535 |
u32 | 32-bit | 0 | 4,294,967,295 |
u64 | 64-bit | 0 | 1.8 * 10^19 |
usize | pointer-sized | 0 | Platform dependent |
Integer Methods
let x: i32 = 42;
let s = x.to_string(); // "42"
let abs = x.abs(); // absolute value
let min = x.min(10); // minimum of two values
let max = x.max(100); // maximum of two values
Integer Literals
let dec = 42; // decimal
let hex = 0xFF; // hexadecimal
let oct = 0o77; // octal
let bin = 0b1010; // binary
let with_sep = 1_000_000; // underscore separator
let typed = 42u8; // type suffix
Floating-Point Types
| Type | Size | Precision | Range | Energy |
|---|---|---|---|---|
f16 | 16-bit | ~3 digits | ~6.1 * 10^-5 to 65504 | 0.4 pJ |
bf16 | 16-bit | ~3 digits | ~1.2 * 10^-38 to ~3.4 * 10^38 | 0.4 pJ |
f32 | 32-bit | ~7 digits | ~1.2 * 10^-38 to ~3.4 * 10^38 | 0.35 pJ |
f64 | 64-bit | ~15 digits | ~2.2 * 10^-308 to ~1.8 * 10^308 | 0.35 pJ |
Half-Precision Types
f16 is IEEE 754 half-precision — useful for signal processing and inference where memory bandwidth matters more than precision.
bf16 (Brain Float) has the same exponent range as f32 but only 8 mantissa bits. Designed for ML training where gradients don't need full precision. Used natively on Google TPUs, NVIDIA A100+, and Apple Neural Engine.
let weight: f16 = 0.5f16;
let grad: bf16 = 0.001bf16;
// Convert to/from f32
let full: f32 = weight as f32;
let half: f16 = full as f16;
Float Methods
let x: f64 = 3.14;
let s = x.to_string(); // "3.14"
let abs = x.abs(); // absolute value
let sqrt = x.sqrt(); // square root
let floor = x.floor(); // round down
let ceil = x.ceil(); // round up
let round = x.round(); // round to nearest
Float Literals
let a = 3.14; // f64 (default)
let b = 3.14f32; // f32
let c = 1.0e10; // scientific notation
let d = 2.5e-3; // 0.0025
Boolean
let t: bool = true;
let f: bool = false;
Boolean Operations
let and = a && b; // logical AND (short-circuit)
let or = a || b; // logical OR (short-circuit)
let not = !a; // logical NOT
Character
A Unicode scalar value (4 bytes):
let c: char = 'A';
let emoji: char = '\u{1F600}';
let newline: char = '\n';
Unit Type
The unit type () represents no meaningful value:
fn do_something() {
// implicitly returns ()
}
let unit: () = ();
Type Conversions
Use as for numeric conversions:
let i: i32 = 42;
let f: f64 = i as f64; // 42.0
let u: u8 = i as u8; // 42 (truncates if > 255)
let s: usize = i as usize; // 42
Conversions are explicit -- Joule does not implicitly convert between numeric types.