Skip to Content
Cloth

Integers

Cloth provides eight fixed-width integer types: four signed and four unsigned. Every integer type has a precise, platform-independent bit width and value range.

Signed integers

Signed integers are stored in two’s-complement form. The most significant bit is the sign bit; the remaining bits encode magnitude.

TypeBitsMinimumMaximum
i88−128127
i1616−32,76832,767
i3232−2,147,483,6482,147,483,647
i6464−9,223,372,036,854,775,8089,223,372,036,854,775,807

Unsigned integers

Unsigned integers represent only non-negative values. All bits encode magnitude.

TypeBitsMinimumMaximum
u880255
u1616065,535
u323204,294,967,295
u6464018,446,744,073,709,551,615

Aliases

The following names are aliases for fixed-width integer types. They exist for readability and for compatibility with naming conventions from other languages.

AliasNotes
intA signed integer; the standard convenience name.
uintAn unsigned integer.
unsignedSynonym for uint.
shortA short signed integer.
longA long signed integer.
byteAn 8-bit value (see Boolean, Char, and Byte).

Literals

Integer literals are written as decimal digit sequences. They take the smallest type that can represent them, with i32 as the default.

let x = 1; let y = 1000000;

Arithmetic

The standard arithmetic operators apply to all integer types: +, -, *, /, %. Comparison operators (==, !=, <, <=, >, >=) and bitwise operators (&, |, ^, ~, <<, >>) are also defined.

Operands of binary arithmetic operators must have the same type. Mixing differently sized or differently signed integers requires an explicit cast (see Operators).

Use in declarations

Integer types appear in field, parameter, variable, and return-type positions:

private i32 v; public Foo(i32 x) { v = x; } public func get(): i32 { return v; }

I/O

The standard library provides println overloads for i32, i64, u32, and u64:

import cloth.io.Out::{ println }; println(42);

The full set of overloads is described in cloth.io.Out.