This module contains the definition of signed fixed width integer types as well as basic arithmetic and bitwise operations on top of it.
The type of signed 8-bit integers. This type has special support in the
compiler to make it actually 8 bits rather than wrapping a Nat
.
- ofUInt8 :: (
- toUInt8 : UInt8
- )
Instances For
- Int8.instNeg
- Int8.instOfNat
- Lean.instToExprInt8
- instAddInt8
- instAndOpInt8
- instComplementInt8
- instDivInt8
- instHashableInt8
- instInhabitedInt8
- instLEInt8
- instLTInt8
- instMaxInt8
- instMinInt8
- instModInt8
- instMulInt8
- instOrOpInt8
- instReprAtomInt8
- instReprInt8
- instShiftLeftInt8
- instShiftRightInt8
- instSubInt8
- instToStringInt8
- instXorInt8
The type of signed 16-bit integers. This type has special support in the
compiler to make it actually 16 bits rather than wrapping a Nat
.
- ofUInt16 :: (
- toUInt16 : UInt16
- )
Instances For
- Int16.instNeg
- Int16.instOfNat
- Lean.instToExprInt16
- instAddInt16
- instAndOpInt16
- instComplementInt16
- instDivInt16
- instHashableInt16
- instInhabitedInt16
- instLEInt16
- instLTInt16
- instMaxInt16
- instMinInt16
- instModInt16
- instMulInt16
- instOrOpInt16
- instReprAtomInt16
- instReprAtomInt16_1
- instReprInt16
- instReprInt16_1
- instShiftLeftInt16
- instShiftRightInt16
- instSubInt16
- instToStringInt16
- instXorInt16
The type of signed 32-bit integers. This type has special support in the
compiler to make it actually 32 bits rather than wrapping a Nat
.
- ofUInt32 :: (
- toUInt32 : UInt32
- )
Instances For
- Int32.instNeg
- Int32.instOfNat
- Lean.instToExprInt32
- instAddInt32
- instAndOpInt32
- instComplementInt32
- instDivInt32
- instHashableInt32
- instInhabitedInt32
- instLEInt32
- instLTInt32
- instMaxInt32
- instMinInt32
- instModInt32
- instMulInt32
- instOrOpInt32
- instShiftLeftInt32
- instShiftRightInt32
- instSubInt32
- instToStringInt32
- instXorInt32
The type of signed 64-bit integers. This type has special support in the
compiler to make it actually 64 bits rather than wrapping a Nat
.
- ofUInt64 :: (
- toUInt64 : UInt64
- )
Instances For
- Int64.instNeg
- Int64.instOfNat
- Lean.instToExprInt64
- instAddInt64
- instAndOpInt64
- instComplementInt64
- instDivInt64
- instHashableInt64
- instInhabitedInt64
- instLEInt64
- instLTInt64
- instMaxInt64
- instMinInt64
- instModInt64
- instMulInt64
- instOrOpInt64
- instReprAtomInt64
- instReprInt64
- instShiftLeftInt64
- instShiftRightInt64
- instSubInt64
- instToStringInt64
- instXorInt64
A ISize
is a signed integer with the size of a word for the platform's architecture.
For example, if running on a 32-bit machine, ISize is equivalent to Int32
.
Or on a 64-bit machine, Int64
.
- ofUSize :: (
- toUSize : USize
- )
Instances For
- ISize.instNeg
- ISize.instOfNat
- Lean.instToExprISize
- instAddISize
- instAndOpISize
- instComplementISize
- instDivISize
- instHashableISize
- instInhabitedISize
- instLEISize
- instLTISize
- instMaxISize
- instMinISize
- instModISize
- instMulISize
- instOrOpISize
- instReprAtomISize
- instReprISize
- instShiftLeftISize
- instShiftRightISize
- instSubISize
- instToStringISize
- instXorISize
Equations
- Int8.ofInt i = { toUInt8 := { toBitVec := BitVec.ofInt 8 i } }
Equations
- Int8.ofNat n = { toUInt8 := { toBitVec := BitVec.ofNat 8 n } }
Obtains the Int8
whose 2's complement representation is the given BitVec 8
.
Equations
- Int8.ofBitVec b = { toUInt8 := { toBitVec := b } }
Equations
- instToStringInt8 = { toString := fun (i : Int8) => toString i.toInt }
Equations
- instHashableInt8 = { hash := fun (i : Int8) => i.toUInt8.toUInt64 }
Equations
- Int8.instOfNat = { ofNat := Int8.ofNat n }
The maximum value an Int8
may attain, that is, 2^7 - 1 = 127
.
Equations
- Int8.maxValue = 127
The minimum value an Int8
may attain, that is, -2^7 = -128
.
Equations
- Int8.minValue = -128
Constructs an Int8
from an Int
which is known to be in bounds.
Equations
- Int8.ofIntLE i _hl _hr = Int8.ofInt i
Constructs an Int8
from an Int
, clamping if the value is too small or too large.
Equations
- Int8.ofIntTruncate i = if hl : Int8.minValue.toInt ≤ i then if hr : i ≤ Int8.maxValue.toInt then Int8.ofIntLE i hl hr else Int8.minValue else Int8.minValue
Equations
- a.shiftRight b = { toUInt8 := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod 8) } }
Equations
- a.complement = { toUInt8 := { toBitVec := ~~~a.toBitVec } }
Computes the absolute value of the signed integer. This function is equivalent to
if a < 0 then -a else a
, so in particular Int8.minValue
will be mapped to Int8.minValue
.
Equations
- instComplementInt8 = { complement := Int8.complement }
Equations
- instShiftLeftInt8 = { shiftLeft := Int8.shiftLeft }
Equations
- instShiftRightInt8 = { shiftRight := Int8.shiftRight }
Equations
- instDecidableLtInt8 a b = a.decLt b
Equations
- instDecidableLeInt8 a b = a.decLe b
Equations
- Int16.ofInt i = { toUInt16 := { toBitVec := BitVec.ofInt 16 i } }
Equations
- Int16.ofNat n = { toUInt16 := { toBitVec := BitVec.ofNat 16 n } }
Obtains the Int16
whose 2's complement representation is the given BitVec 16
.
Equations
- Int16.ofBitVec b = { toUInt16 := { toBitVec := b } }
Equations
- a.toInt8 = { toUInt8 := { toBitVec := BitVec.signExtend 8 a.toBitVec } }
Equations
- a.toInt16 = { toUInt16 := { toBitVec := BitVec.signExtend 16 a.toBitVec } }
Equations
- instToStringInt16 = { toString := fun (i : Int16) => toString i.toInt }
Equations
- instHashableInt16 = { hash := fun (i : Int16) => i.toUInt16.toUInt64 }
Equations
- Int16.instOfNat = { ofNat := Int16.ofNat n }
The maximum value an Int16
may attain, that is, 2^15 - 1 = 32767
.
Equations
- Int16.maxValue = 32767
The minimum value an Int16
may attain, that is, -2^15 = -32768
.
Equations
- Int16.minValue = -32768
Constructs an Int16
from an Int
which is known to be in bounds.
Equations
- Int16.ofIntLE i _hl _hr = Int16.ofInt i
Constructs an Int16
from an Int
, clamping if the value is too small or too large.
Equations
- Int16.ofIntTruncate i = if hl : Int16.minValue.toInt ≤ i then if hr : i ≤ Int16.maxValue.toInt then Int16.ofIntLE i hl hr else Int16.minValue else Int16.minValue
Equations
- a.shiftRight b = { toUInt16 := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod 16) } }
Equations
- a.complement = { toUInt16 := { toBitVec := ~~~a.toBitVec } }
Computes the absolute value of the signed integer. This function is equivalent to
if a < 0 then -a else a
, so in particular Int16.minValue
will be mapped to Int16.minValue
.
Equations
- instComplementInt16 = { complement := Int16.complement }
Equations
- instShiftLeftInt16 = { shiftLeft := Int16.shiftLeft }
Equations
- instShiftRightInt16 = { shiftRight := Int16.shiftRight }
Equations
- instDecidableLtInt16 a b = a.decLt b
Equations
- instDecidableLeInt16 a b = a.decLe b
The size of type Int32
, that is, 2^32 = 4294967296
.
Equations
- Int32.size = 4294967296
Equations
- Int32.ofInt i = { toUInt32 := { toBitVec := BitVec.ofInt 32 i } }
Equations
- Int32.ofNat n = { toUInt32 := { toBitVec := BitVec.ofNat 32 n } }
Obtains the Int32
whose 2's complement representation is the given BitVec 32
.
Equations
- Int32.ofBitVec b = { toUInt32 := { toBitVec := b } }
Equations
- a.toInt8 = { toUInt8 := { toBitVec := BitVec.signExtend 8 a.toBitVec } }
Equations
- a.toInt16 = { toUInt16 := { toBitVec := BitVec.signExtend 16 a.toBitVec } }
Equations
- a.toInt32 = { toUInt32 := { toBitVec := BitVec.signExtend 32 a.toBitVec } }
Equations
- a.toInt32 = { toUInt32 := { toBitVec := BitVec.signExtend 32 a.toBitVec } }
Equations
- instToStringInt32 = { toString := fun (i : Int32) => toString i.toInt }
Equations
- instHashableInt32 = { hash := fun (i : Int32) => i.toUInt32.toUInt64 }
Equations
- Int32.instOfNat = { ofNat := Int32.ofNat n }
The maximum value an Int32
may attain, that is, 2^31 - 1 = 2147483647
.
Equations
- Int32.maxValue = 2147483647
The minimum value an Int32
may attain, that is, -2^31 = -2147483648
.
Equations
- Int32.minValue = -2147483648
Constructs an Int32
from an Int
which is known to be in bounds.
Equations
- Int32.ofIntLE i _hl _hr = Int32.ofInt i
Constructs an Int32
from an Int
, clamping if the value is too small or too large.
Equations
- Int32.ofIntTruncate i = if hl : Int32.minValue.toInt ≤ i then if hr : i ≤ Int32.maxValue.toInt then Int32.ofIntLE i hl hr else Int32.minValue else Int32.minValue
Equations
- a.shiftRight b = { toUInt32 := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod 32) } }
Equations
- a.complement = { toUInt32 := { toBitVec := ~~~a.toBitVec } }
Computes the absolute value of the signed integer. This function is equivalent to
if a < 0 then -a else a
, so in particular Int32.minValue
will be mapped to Int32.minValue
.
Equations
- instComplementInt32 = { complement := Int32.complement }
Equations
- instShiftLeftInt32 = { shiftLeft := Int32.shiftLeft }
Equations
- instShiftRightInt32 = { shiftRight := Int32.shiftRight }
Equations
- instDecidableLtInt32 a b = a.decLt b
Equations
- instDecidableLeInt32 a b = a.decLe b
The size of type Int64
, that is, 2^64 = 18446744073709551616
.
Equations
- Int64.size = 18446744073709551616
Equations
- Int64.ofInt i = { toUInt64 := { toBitVec := BitVec.ofInt 64 i } }
Equations
- Int64.ofNat n = { toUInt64 := { toBitVec := BitVec.ofNat 64 n } }
Obtains the Int64
whose 2's complement representation is the given BitVec 64
.
Equations
- Int64.ofBitVec b = { toUInt64 := { toBitVec := b } }
Equations
- a.toInt8 = { toUInt8 := { toBitVec := BitVec.signExtend 8 a.toBitVec } }
Equations
- a.toInt16 = { toUInt16 := { toBitVec := BitVec.signExtend 16 a.toBitVec } }
Equations
- a.toInt32 = { toUInt32 := { toBitVec := BitVec.signExtend 32 a.toBitVec } }
Equations
- a.toInt64 = { toUInt64 := { toBitVec := BitVec.signExtend 64 a.toBitVec } }
Equations
- a.toInt64 = { toUInt64 := { toBitVec := BitVec.signExtend 64 a.toBitVec } }
Equations
- a.toInt64 = { toUInt64 := { toBitVec := BitVec.signExtend 64 a.toBitVec } }
Equations
- instToStringInt64 = { toString := fun (i : Int64) => toString i.toInt }
Equations
- instHashableInt64 = { hash := fun (i : Int64) => i.toUInt64 }
Equations
- Int64.instOfNat = { ofNat := Int64.ofNat n }
The maximum value an Int64
may attain, that is, 2^63 - 1 = 9223372036854775807
.
Equations
- Int64.maxValue = 9223372036854775807
The minimum value an Int64
may attain, that is, -2^63 = -9223372036854775808
.
Equations
- Int64.minValue = -9223372036854775808
Constructs an Int64
from an Int
which is known to be in bounds.
Equations
- Int64.ofIntLE i _hl _hr = Int64.ofInt i
Constructs an Int64
from an Int
, clamping if the value is too small or too large.
Equations
- Int64.ofIntTruncate i = if hl : Int64.minValue.toInt ≤ i then if hr : i ≤ Int64.maxValue.toInt then Int64.ofIntLE i hl hr else Int64.minValue else Int64.minValue
Equations
- a.shiftRight b = { toUInt64 := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod 64) } }
Equations
- a.complement = { toUInt64 := { toBitVec := ~~~a.toBitVec } }
Computes the absolute value of the signed integer. This function is equivalent to
if a < 0 then -a else a
, so in particular Int64.minValue
will be mapped to Int64.minValue
.
Equations
- instComplementInt64 = { complement := Int64.complement }
Equations
- instShiftLeftInt64 = { shiftLeft := Int64.shiftLeft }
Equations
- instShiftRightInt64 = { shiftRight := Int64.shiftRight }
Equations
- instDecidableLtInt64 a b = a.decLt b
Equations
- instDecidableLeInt64 a b = a.decLe b
Equations
- ISize.ofInt i = { toUSize := { toBitVec := BitVec.ofInt System.Platform.numBits i } }
Equations
- ISize.ofNat n = { toUSize := { toBitVec := BitVec.ofNat System.Platform.numBits n } }
Obtains the ISize
whose 2's complement representation is the given BitVec
.
Equations
- ISize.ofBitVec b = { toUSize := { toBitVec := b } }
Equations
- a.toInt8 = { toUInt8 := { toBitVec := BitVec.signExtend 8 a.toBitVec } }
Equations
- a.toInt16 = { toUInt16 := { toBitVec := BitVec.signExtend 16 a.toBitVec } }
Equations
- a.toInt32 = { toUInt32 := { toBitVec := BitVec.signExtend 32 a.toBitVec } }
Equations
- a.toISize = { toUSize := { toBitVec := BitVec.signExtend System.Platform.numBits a.toBitVec } }
Equations
- a.toISize = { toUSize := { toBitVec := BitVec.signExtend System.Platform.numBits a.toBitVec } }
Upcasts Int32
to ISize
. This function is lossless as ISize
is either Int32
or Int64
.
Equations
- a.toISize = { toUSize := { toBitVec := BitVec.signExtend System.Platform.numBits a.toBitVec } }
Equations
- a.toISize = { toUSize := { toBitVec := BitVec.signExtend System.Platform.numBits a.toBitVec } }
Equations
- instToStringISize = { toString := fun (i : ISize) => toString i.toInt }
Equations
- instHashableISize = { hash := fun (i : ISize) => i.toUSize.toUInt64 }
Equations
- ISize.instOfNat = { ofNat := ISize.ofNat n }
The maximum value an ISize
may attain, that is, 2^(System.Platform.numBits - 1) - 1
.
Equations
- ISize.maxValue = ISize.ofInt (2 ^ (System.Platform.numBits - 1) - 1)
The minimum value an ISize
may attain, that is, -2^(System.Platform.numBits - 1)
.
Equations
- ISize.minValue = ISize.ofInt (-2 ^ (System.Platform.numBits - 1))
Constructs an ISize
from an Int
which is known to be in bounds.
Equations
- ISize.ofIntLE i _hl _hr = ISize.ofInt i
Constructs an ISize
from an Int
, clamping if the value is too small or too large.
Equations
- ISize.ofIntTruncate i = if hl : ISize.minValue.toInt ≤ i then if hr : i ≤ ISize.maxValue.toInt then ISize.ofIntLE i hl hr else ISize.minValue else ISize.minValue
Equations
- a.shiftRight b = { toUSize := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod ↑System.Platform.numBits) } }
Equations
- a.complement = { toUSize := { toBitVec := ~~~a.toBitVec } }
Computes the absolute value of the signed integer. This function is equivalent to
if a < 0 then -a else a
, so in particular ISize.minValue
will be mapped to ISize.minValue
.
Equations
- instComplementISize = { complement := ISize.complement }
Equations
- instShiftLeftISize = { shiftLeft := ISize.shiftLeft }
Equations
- instShiftRightISize = { shiftRight := ISize.shiftRight }
Equations
- instDecidableLtISize a b = a.decLt b
Equations
- instDecidableLeISize a b = a.decLe b