Skip to content

Literals

Decimal Literals

42
1_000_000 // underscores for readability

Base Prefixes

0xFF // hexadecimal: 255
0b1010 // binary: 10
0o755 // octal: 493

Underscores work with all bases:

0xFF_FF_FF_FF // 4294967295
0b1111_0000 // 240

Integer Type Suffixes

Force a specific integer type with a trailing suffix:

42_i8 // int8
42_i16 // int16
42_i32 // int32
42_i64 // int64
255_u8 // uint8
1000_u16 // uint16
0xFF_u32 // uint32
100_nint // native int
256_nuint // native uint

Float Literals

3.14
3.141_592_653 // underscores in floats

Float Type Suffixes

3.14_f32 // float32
3.14_f64 // float64
42_f32 // integer as float32

Hex Float Literals

IEEE 754 hex float notation for exact representation:

0x1.0p0 // 1.0
0x1.0p1 // 2.0 (1.0 * 2^1)
0x1.0p-1 // 0.5
0x1.8p0 // 1.5
0x1.0p0_f32 // float32

String Escape Sequences

String literals support the following escape sequences:

EscapeCharacterCode Point
\nNewline10
\tTab9
\rCarriage return13
\\Backslash92
\"Double quote34
\0Null0
\bBackspace8
\fForm feed12
string msg = "Hello\nWorld"; // two lines
string path = "C:\\Users\\file"; // backslashes
string tab = "col1\tcol2"; // tab-separated
string quoted = "She said \"hi\""; // embedded quotes

Character Literals

Character literals evaluate to their integer code point:

'A' // 65
'\n' // 10 (newline)
'\t' // 9 (tab)
'\\' // 92 (backslash)
'\x41' // 65 (hex escape)
'\xFF' // 255