Checked integer widths and packed arrays
Keep Int64 inference while choosing compact signed or unsigned arrays, exact large values and checked arithmetic.
// Integer inference stays Int64; explicit representations belong to Number.
let ordinary = 42
let sample: Int16 = -32000
let pixel = UInt8(255)
let large: UInt64 = 18446744073709551615
let same_large = UInt64(18446744073709551615)
print(type(ordinary)) // Int64
print(dtype(sample)) // Int16
print(type(pixel)) // UInt8
print(large == same_large) // true
print(large > 9223372036854775807) // true
var numeric: Number = pixel
print(type(numeric)) // UInt8
numeric = sample
print(type(numeric)) // Int16
numeric = 2.5
print(type(numeric)) // Float64
let source: Int64 = 200
let byte: UInt8 = source
let wider: UInt32 = byte
print(byte) // 200
print(type(wider)) // UInt32
print(Int16(3.9)) // 3
print(Int16(-3.9)) // -3
print(type(Int8(2) + UInt8(3))) // Int16
print(type(UInt8(250) + 1)) // Int64
print(integer_div(Int16(-7), Int16(3))) // -2
print(Int16(-7) % Int16(3)) // -1
let pixels = Array<UInt8>(size: 4, fill: 0)
pixels[0] = 255
pixels.set(1, 128)
print(dtype(pixels)) // UInt8
print(type(pixels.get(0))) // UInt8
print(pixels.to_list()) // List(255, 128, 0, 0)
let samples = DynamicArray<Int16>(capacity: 2)
samples.append(-100)
samples.append(200)
print(samples.sum()) // 100
print(type(samples.sum())) // Int16
let matrix = NDArray<Int32>(shape: List(2, 2), fill: 3)
print(matrix.matmul(matrix).to_list()) // List(18, 18, 18, 18)
let floating = samples.to_float()
print(dtype(floating)) // Float64
print(type(Float64(large))) // Float64: explicit permission to round
// Checked failures, intentionally disabled:
// let invalid: Int8 = source // R1003: 200 exceeds 127
// print(UInt8(-0.5)) // R1003: unsigned conversions reject negative floats
// print(UInt8(250) + UInt8(10)) // R0001: UInt8 scalar overflow
// print(large + 1) // no lossless common integer type with signed Int64
// pixels.set(0, 300) // R1003: scalar conversion fails before mutation
// print(pixels.sum()) // R3001: 383 exceeds UInt8; array sum retains dtype
Make it your experiment.
With a compatible development runtime installed, save this program as examples/integer_types.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.
aner check examples/integer_types.aner
aner run examples/integer_types.anerThe aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.
Requires a compatible current native Aner development runtime with all eight fixed width integer types and packed integer arrays. These numeric additions await a matching published binary; the existing research preview may not recognize them. Use matching local VS Code integration for editor help. Development runtimes and extension packages are not offered by this website. The complete example needs no external data, network connection or credentials.
Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.
Dataset sources & attribution