Core typesPrimitive types
Primitive types
The types built into the language: truth values, characters, integers and floats. One page per type.
A primitive type is built into the compiler. Its values are small, it is always copied rather than moved, and its methods come with the type, so nothing is imported to call x.abs() or c.isDigit().
Each type has its own page: what it is, how a value is written, every operator and method, what happens at the edges, and what is not finished.
| Type | What it is | Page |
|---|---|---|
bool | true or false. | bool |
char | One Unicode scalar value. | char |
int | The default signed integer, 64 bits. | int |
int8, int16, int32 | Signed integers of a given width. | int8, int16, int32 |
int64 | Another name for int. | int64 |
uint8, uint16, uint32, uint64 | Unsigned integers of a given width. | uint8, uint16, uint32, uint64 |
byte, uint | Other names for uint8 and uint64. | byte, uint |
int128, uint128, int256, uint256 | Wide integers with the same checked arithmetic. | int128, uint128, int256, uint256 |
float | The default floating point number, 64 bits. | float |
float32, float16, float128, float256 | Other IEEE 754 binary formats. | float32, float16, float128, float256 |
Overviews of the wide types: Wide integers and Wide and narrow floats.
Rules every primitive shares
- Value semantics. Assigning, passing or returning a primitive copies it. There is no
inoutorsinkto think about for a plainint. - No implicit conversions.
intandfloatare never mixed silently.n to floatis written out; see Conversions. - Checked arithmetic. An integer result that does not fit stops the program with
stopped: arithmetic overflow. The%forms (+%,-%,*%) wrap on purpose. - Printing. Every primitive can be put in a
#( )string and passed toprint.