Skip to content

Commit 4678e2d

Browse files
committed
Introduce hex and binary literals before the signed type rule
The page jumped from a one-line mention of hex straight into the signed-type edge case. Restructure: explain what hex and binary prefixes are and that the three notations are equivalent, then the signed range rule follows naturally.
1 parent d3aad7f commit 4678e2d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎docs/expressions/literals.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ It is possible to help the compiler determine the concrete type of the literal u
3434
--8<-- "literals-numeric-typing.pony"
3535
```
3636

37-
Integer literals can be given as decimal, hexadecimal or binary:
37+
### Hex and Binary Literals
38+
39+
Integer literals can be written in hexadecimal with the `0x` prefix or binary with the `0b` prefix. They represent the same values as their decimal equivalents:
3840

3941
```pony
4042
--8<-- "literals-number-types.pony:3:5"
4143
```
4244

43-
### Hex Literals on Signed Types
45+
All three lines above assign 1024 to an I32.
4446

45-
A hex literal like `0x80000000` looks like it should fit in an I32, but it is the positive value 2,147,483,648 — one more than I32's maximum of 2,147,483,647. The compiler rejects any literal whose value exceeds the signed type's maximum:
47+
Hex and binary literals are always positive values. The compiler rejects a literal whose value exceeds the signed type's maximum. A hex literal like `0x80000000` is the positive value 2,147,483,648, one more than I32's maximum of 2,147,483,647:
4648

4749
```pony
4850
let x: I32 = 0x80000000

0 commit comments

Comments
 (0)