Integer types
Integers represent whole numbers. Pop provides four signed widths and four unsigned widths.
| Type | Minimum | Maximum |
|---|---|---|
Int8 |
-128 | 127 |
Int16 |
-32,768 | 32,767 |
Int32 |
-2,147,483,648 | 2,147,483,647 |
Int64 / Int |
-9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
UInt8 / Byte |
0 | 255 |
UInt16 |
0 | 65,535 |
UInt32 |
0 | 4,294,967,295 |
UInt64 |
0 | 18,446,744,073,709,551,615 |
Use Int for ordinary whole-number work. Choose a fixed width when a file format, protocol, native interface, or memory layout requires it. Unsigned types are appropriate when the represented format is explicitly unsigned; they are not a substitute for validating that a value is nonnegative.
Writing integer literals
Section titled “Writing integer literals”Integer literals use decimal digits. Underscores may separate groups for readability:
local population = 8_100_000_000local mask: UInt8 = 255The underscore does not change the value. This release does not implement hexadecimal, octal, or binary literal prefixes.
A negative value is written by applying unary - to a literal or another signed expression:
local temperature = -12Unsigned values do not support unary negation.
Checked arithmetic
Section titled “Checked arithmetic”Pop checks +, -, and * against the range of their exact type. If a result cannot be represented, execution traps:
local maximum: UInt8 = 255local overflow = maximum + 1 -- trapsDivision and remainder trap when the divisor is zero. Signed division also traps when dividing the minimum value by -1, because the positive result is one larger than the type can represent.
No arithmetic promotion is performed. Both operands must already have the same type:
local left: Int32 = 10local right: Int64 = 20local total = left + right -- type errorExplicit conversion
Section titled “Explicit conversion”Convert between numeric types with a target-type call:
local count: Int = 120local compact = UInt8(count)local ratio = Float64(count)Conversions are never implicit. Integer narrowing and float-to-integer conversion trap with NumericConversion when the result is invalid or outside the target range. Float-to-integer conversion truncates toward zero.
Use the individual primitive pages for focused examples and ranges.
The Numeric conversions leaf lists every conversion family and its failure rules.
