///|
test "int16 range" {
inspect(@int16.MIN_VALUE, content="-32768")
inspect(@int16.MAX_VALUE, content="32767")
}///|
test "int16 arithmetic" {
let a : Int16 = 100
let b : Int16 = 50
// Basic arithmetic
inspect(a + b, content="150")
inspect(a - b, content="50")
inspect(a * b, content="5000")
inspect(a / b, content="2")
// Overflow behavior
let max = @int16.MAX_VALUE
let min = @int16.MIN_VALUE
inspect(max + 1, content="-32768") // Wraps around to MIN_VALUE
inspect(min - 1, content="32767") // Wraps around to MAX_VALUE
}///|
test "int16 bitwise" {
let a : Int16 = 0b1100
let b : Int16 = 0b1010
// Bitwise AND, OR, XOR
inspect(a & b, content="8") // 0b1000
inspect(a | b, content="14") // 0b1110
inspect(a ^ b, content="6") // 0b0110
// Bit shifts
let x : Int16 = 8
inspect(x << 1, content="16") // Left shift
inspect(x >> 1, content="4") // Right shift
}///|
test "int16 comparison" {
let a : Int16 = 100
let b : Int16 = 50
let c : Int16 = 100
// Equality
inspect(a == b, content="false")
inspect(a == c, content="true")
// Ordering
inspect(a > b, content="true")
inspect(b < c, content="true")
// Compare function returns -1, 0, or 1
inspect(a.compare(b), content="1")
inspect(b.compare(c), content="-1")
inspect(a.compare(c), content="0")
}///|
test "int16 default" {
let x = (Default::default() : Int16)
inspect(x, content="0")
}///|
test "int16 coercion" {
let a : Int16 = 42 // Coercion from integer literal
let b : Int16 = 0xFF // Hexadecimal literal
let c : Int16 = 0b1111 // Binary literal
inspect(a, content="42")
inspect(b, content="255")
inspect(c, content="15")
}Int16 is a built-in type. The documentation may not be complete here. You can find all methods and implementations in the core/builtin and core/int16 package.
fn Int16::from_byte(self : Byte) -> Int16test {
let b = b'\xFF'
inspect(Int16::from_byte(b), content="255") // Sign is preserved
let p = b'\x7F'
inspect(Int16::from_byte(p), content="127")
}fn Int16::from_int(self : Int) -> Int16test {
let n = Int16::from_int(42)
inspect(n, content="42")
let neg = Int16::from_int(-42)
inspect(neg, content="-42")
}fn Int16::from_int64(self : Int64) -> Int16test {
let big = 100000L
inspect(Int16::from_int64(big), content="-31072") // 100000 doesn't fit in Int16, gets truncated
let small = 42L
inspect(Int16::from_int64(small), content="42") // 42 fits in Int16, remains unchanged
}fn Int16::lnot(self : Int16) -> Int16test {
inspect((0 : Int16).lnot(), content="-1")
inspect((-1 : Int16).lnot(), content="0")
}fn Int16::reinterpret_as_uint16(self : Int16) -> UInt16fn Int16::reinterpret_from_uint16(self : UInt16) -> Int16fn Int16::to_byte(self : Int16) -> Bytetest {
let x : Int16 = 258 // In binary: 0000_0001_0000_0010
inspect(x.to_byte(), content="b'\\x02'") // Only keeps 0000_0010
}fn Int16::to_int(self : Int16) -> Inttest {
let n = (42 : Int16)
inspect(n.to_int(), content="42")
let neg = (-42 : Int16)
inspect(neg.to_int(), content="-42")
}#deprecated("Use `MAX_VALUE` instead")
let max_value : Int16#deprecated("Use `MIN_VALUE` instead")
let min_value : Int16Install
Installed by default