///|
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")
}pub type Int16fn Int16::Int16(self : Int16) -> Int16test {
inspect(Int16(3), content="3")
}fn Int16::clamp(self : Int16, min~ : Int16, max~ : Int16) -> Int16test {
inspect(Int16(5).clamp(min=Int16(0), max=Int16(10)), content="5")
inspect(Int16(-5).clamp(min=Int16(0), max=Int16(10)), content="0")
inspect(Int16(15).clamp(min=Int16(0), max=Int16(10)), content="10")
}fn Int16::clz(self : Int16) -> Inttest {
inspect(Int16(1).clz(), content="15")
inspect(Int16(-1).clz(), content="0")
inspect(Int16(0).clz(), content="16")
}fn Int16::ctz(self : Int16) -> Inttest {
inspect(Int16(8).ctz(), content="3")
inspect(@int16.MIN_VALUE.ctz(), content="15")
inspect(Int16(0).ctz(), content="16")
}fn Int16::from_byte(self : Byte) -> Int16test {
let b = b'\xFF'
inspect(Int16::from_byte(b), content="255") // Zero-extended, not sign-extended
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) -> Int16#cfg(not(target="js"))
test {
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::from_uint(self : UInt) -> Int16test {
inspect(Int16::from_uint(42U), content="42")
inspect(Int16::from_uint(0xFFFFU), content="-1")
inspect(Int16::from_uint(0x12345U), content="9029")
}fn Int16::from_uint64(self : UInt64) -> Int16test {
inspect(Int16::from_uint64(42UL), content="42")
inspect(Int16::from_uint64(0xFFFFFFFFFFFFFFFFUL), content="-1")
inspect(Int16::from_uint64(0x1_0000_8000UL), content="-32768")
}fn Int16::lnot(self : Int16) -> Int16test {
inspect(Int16(0).lnot(), content="-1")
inspect(Int16(-1).lnot(), content="0")
}fn Int16::max(self : Int16, other : Int16) -> Int16test {
inspect(Int16(1).max(Int16(2)), content="2")
inspect(Int16(-1).max(Int16(1)), content="1")
}fn Int16::min(self : Int16, other : Int16) -> Int16test {
inspect(Int16(1).min(Int16(2)), content="1")
inspect(Int16(-1).min(Int16(1)), content="-1")
}fn Int16::popcnt(self : Int16) -> Inttest {
inspect(Int16(0x0F0F).popcnt(), content="8")
inspect(Int16(-1).popcnt(), content="16")
inspect(Int16(0).popcnt(), 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="2") // Only keeps 0000_0010
}fn Int16::to_double(self : Int16) -> Doubletest {
inspect(Int16(42).to_double(), content="42")
inspect(@int16.MIN_VALUE.to_double(), content="-32768")
}fn Int16::to_int(self : Int16) -> Inttest {
let n = Int16(42)
inspect(n.to_int(), content="42")
let neg = Int16(-42)
inspect(neg.to_int(), content="-42")
}fn Int16::to_uint(self : Int16) -> UInttest {
inspect(Int16(42).to_uint(), content="42")
inspect(Int16(-1).to_uint(), content="4294967295")
inspect(@int16.MIN_VALUE.to_uint(), content="4294934528")
}fn Int16::to_uint64(self : Int16) -> UInt64test {
inspect(Int16(42).to_uint64(), content="42")
inspect(Int16(-1).to_uint64(), content="18446744073709551615")
inspect(@int16.MIN_VALUE.to_uint64(), content="18446744073709518848")
}#deprecated("Use `MAX_VALUE` instead")
let max_value : Int16#deprecated("Use `MIN_VALUE` instead")
let min_value : Int16Install
Installed by default