This module contains the definition of signed fixed width integer types as well as basic arithmetic and bitwise operations on top of it.
Signed integers that are the size of a word on the platform's architecture.
On a 32-bit architecture, ISize
is equivalent to Int32
. On a 64-bit machine, it is equivalent to
Int64
. This type has special support in the compiler so it can be represented by an unboxed value.
- ofUSize :: (
- toUSize : USize
Converts a word-sized signed integer into the word-sized unsigned integer that is its two's complement encoding.
- )
Instances For
Converts an arbitrary-precision integer to an 8-bit integer, wrapping on overflow or underflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int8.ofInt 48 = 48
Int8.ofInt (-115) = -115
Int8.ofInt (-129) = 127
Int8.ofInt (128) = -128
Equations
- Int8.ofInt i = { toUInt8 := { toBitVec := BitVec.ofInt 8 i } }
Instances For
Converts a natural number to an 8-bit signed integer, wrapping around on overflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int8.ofNat 53 = 53
Int8.ofNat 127 = 127
Int8.ofNat 128 = -128
Int8.ofNat 255 = -1
Equations
- Int8.ofNat n = { toUInt8 := { toBitVec := BitVec.ofNat 8 n } }
Instances For
Converts an arbitrary-precision integer to an 8-bit integer, wrapping on overflow or underflow.
Examples:
Int.toInt8 48 = 48
Int.toInt8 (-115) = -115
Int.toInt8 (-129) = 127
Int.toInt8 (128) = -128
Equations
Instances For
Converts a natural number to an 8-bit signed integer, wrapping around to negative numbers on overflow.
Examples:
Nat.toInt8 53 = 53
Nat.toInt8 127 = 127
Nat.toInt8 128 = -128
Nat.toInt8 255 = -1
Equations
Instances For
Converts an 8-bit signed integer to a natural number, mapping all negative numbers to 0
.
Use Int8.toBitVec
to obtain the two's complement representation.
Equations
- i.toNatClampNeg = i.toInt.toNat
Instances For
Converts an 8-bit signed integer to a natural number, mapping all negative numbers to 0
.
Use Int8.toBitVec
to obtain the two's complement representation.
Instances For
Obtains the Int8
whose 2's complement representation is the given BitVec 8
.
Equations
- Int8.ofBitVec b = { toUInt8 := { toBitVec := b } }
Instances For
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 largest number that Int8
can represent: 2^7 - 1 = 127
.
Equations
- Int8.maxValue = 127
Instances For
The smallest number that Int8
can represent: -2^7 = -128
.
Equations
- Int8.minValue = -128
Instances For
Constructs an Int8
from an Int
that is known to be in bounds.
Equations
- Int8.ofIntLE i _hl _hr = Int8.ofInt i
Instances For
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
Instances For
Adds two 8-bit signed integers, wrapping around on over- or underflow. Usually accessed via the +
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Subtracts one 8-bit signed integer from another, wrapping around on over- or underflow. Usually
accessed via the -
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Multiplies two 8-bit signed integers, wrapping around on over- or underflow. Usually accessed via
the *
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Truncating division for 8-bit signed integers, rounding towards zero. Usually accessed via the /
operator.
Division by zero is defined to be zero.
This function is overridden at runtime with an efficient implementation.
Examples:
Int8.div 10 3 = 3
Int8.div 10 (-3) = (-3)
Int8.div (-10) (-3) = 3
Int8.div (-10) 3 = (-3)
Int8.div 10 0 = 0
Instances For
The modulo operator for 8-bit signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by Int8.div
. Usually accessed via the %
operator.
When the divisor is 0
, the result is the dividend rather than an error.
This function is overridden at runtime with an efficient implementation.
Examples:
Int8.mod 5 2 = 1
Int8.mod 5 (-2) = 1
Int8.mod (-5) 2 = (-1)
Int8.mod (-5) (-2) = (-1)
Int8.mod 4 2 = 0
Int8.mod 4 (-2) = 0
Int8.mod 4 0 = 4
Int8.mod (-4) 0 = (-4)
Instances For
Bitwise and for 8-bit signed integers. Usually accessed via the &&&
operator.
Each bit of the resulting integer is set if the corresponding bits of both input integers are set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise or for 8-bit signed integers. Usually accessed via the |||
operator.
Each bit of the resulting integer is set if at least one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise exclusive or for 8-bit signed integers. Usually accessed via the ^^^
operator.
Each bit of the resulting integer is set if exactly one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise left shift for 8-bit signed integers. Usually accessed via the <<<
operator.
Signed integers are interpreted as bitvectors according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Arithmetic right shift for 8-bit signed integers. Usually accessed via the <<<
operator.
The high bits are filled with the value of the most significant bit.
This function is overridden at runtime with an efficient implementation.
Equations
- a.shiftRight b = { toUInt8 := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod 8) } }
Instances For
Bitwise complement, also known as bitwise negation, for 8-bit signed integers. Usually accessed via
the ~~~
prefix operator.
Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so Int8.complement a = -(a + 1)
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.complement = { toUInt8 := { toBitVec := ~~~a.toBitVec } }
Instances For
Computes the absolute value of an 8-bit 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
.
This function is overridden at runtime with an efficient implementation.
Instances For
Decides whether two 8-bit signed integers are equal. Usually accessed via the DecidableEq Int8
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
Int8.decEq 123 123 = .isTrue rfl
(if ((-7) : Int8) = 7 then "yes" else "no") = "no"
show (7 : Int8) = 7 by decide
Instances For
Equations
- instComplementInt8 = { complement := Int8.complement }
Equations
- instShiftLeftInt8 = { shiftLeft := Int8.shiftLeft }
Equations
- instShiftRightInt8 = { shiftRight := Int8.shiftRight }
Decides whether one 8-bit signed integer is strictly less than another. Usually accessed via the
DecidableLT Int8
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : Int8) < 7 then "yes" else "no") = "yes"
(if (5 : Int8) < 5 then "yes" else "no") = "no"
show ¬((7 : Int8) < 7) by decide
Instances For
Decides whether one 8-bit signed integer is less than or equal to another. Usually accessed via the
DecidableLE Int8
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : Int8) ≤ 7 then "yes" else "no") = "yes"
(if (15 : Int8) ≤ 15 then "yes" else "no") = "yes"
(if (15 : Int8) ≤ 5 then "yes" else "no") = "no"
show (7 : Int8) ≤ 7 by decide
Instances For
Equations
- instDecidableLtInt8 a b = a.decLt b
Equations
- instDecidableLeInt8 a b = a.decLe b
The number of distinct values representable by Int16
, that is, 2^16 = 65536
.
Equations
- Int16.size = 65536
Instances For
Converts an arbitrary-precision integer to a 16-bit signed integer, wrapping on overflow or underflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int16.ofInt 48 = 48
Int16.ofInt (-129) = -129
Int16.ofInt (128) = 128
Int16.ofInt 70000 = 4464
Int16.ofInt (-40000) = 25536
Equations
- Int16.ofInt i = { toUInt16 := { toBitVec := BitVec.ofInt 16 i } }
Instances For
Converts a natural number to a 16-bit signed integer, wrapping around on overflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int16.ofNat 127 = 127
Int16.ofNat 32767 = 32767
Int16.ofNat 32768 = -32768
Int16.ofNat 32770 = -32766
Equations
- Int16.ofNat n = { toUInt16 := { toBitVec := BitVec.ofNat 16 n } }
Instances For
Converts an arbitrary-precision integer to a 16-bit integer, wrapping on overflow or underflow.
Examples:
Int.toInt16 48 = 48
Int.toInt16 (-129) = -129
Int.toInt16 (128) = 128
Int.toInt16 70000 = 4464
Int.toInt16 (-40000) = 25536
Equations
Instances For
Converts a natural number to a 16-bit signed integer, wrapping around to negative numbers on overflow.
Examples:
Nat.toInt16 127 = 127
Nat.toInt16 32767 = 32767
Nat.toInt16 32768 = -32768
Nat.toInt16 32770 = -32766
Equations
Instances For
Converts a 16-bit signed integer to a natural number, mapping all negative numbers to 0
.
Use Int16.toBitVec
to obtain the two's complement representation.
Equations
- i.toNatClampNeg = i.toInt.toNat
Instances For
Converts a 16-bit signed integer to a natural number, mapping all negative numbers to 0
.
Use Int16.toBitVec
to obtain the two's complement representation.
Instances For
Obtains the Int16
whose 2's complement representation is the given BitVec 16
.
Equations
- Int16.ofBitVec b = { toUInt16 := { toBitVec := b } }
Instances For
Converts 16-bit signed integers to 8-bit signed integers by truncating their bitvector representation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt8 = { toUInt8 := { toBitVec := BitVec.signExtend 8 a.toBitVec } }
Instances For
Converts 8-bit signed integers to 16-bit signed integers that denote the same number.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt16 = { toUInt16 := { toBitVec := BitVec.signExtend 16 a.toBitVec } }
Instances For
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 largest number that Int16
can represent: 2^15 - 1 = 32767
.
Equations
- Int16.maxValue = 32767
Instances For
The smallest number that Int16
can represent: -2^15 = -32768
.
Equations
- Int16.minValue = -32768
Instances For
Constructs an Int16
from an Int
that is known to be in bounds.
Equations
- Int16.ofIntLE i _hl _hr = Int16.ofInt i
Instances For
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
Instances For
Adds two 16-bit signed integers, wrapping around on over- or underflow. Usually accessed via the +
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Subtracts one 16-bit signed integer from another, wrapping around on over- or underflow. Usually
accessed via the -
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Multiplies two 16-bit signed integers, wrapping around on over- or underflow. Usually accessed via
the *
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Truncating division for 16-bit signed integers, rounding towards zero. Usually accessed via the /
operator.
Division by zero is defined to be zero.
This function is overridden at runtime with an efficient implementation.
Examples:
Int16.div 10 3 = 3
Int16.div 10 (-3) = (-3)
Int16.div (-10) (-3) = 3
Int16.div (-10) 3 = (-3)
Int16.div 10 0 = 0
Instances For
The modulo operator for 16-bit signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by Int16.div
. Usually accessed via the %
operator.
When the divisor is 0
, the result is the dividend rather than an error.
This function is overridden at runtime with an efficient implementation.
Examples:
Int16.mod 5 2 = 1
Int16.mod 5 (-2) = 1
Int16.mod (-5) 2 = (-1)
Int16.mod (-5) (-2) = (-1)
Int16.mod 4 2 = 0
Int16.mod 4 (-2) = 0
Int16.mod 4 0 = 4
Int16.mod (-4) 0 = (-4)
Instances For
Bitwise and for 16-bit signed integers. Usually accessed via the &&&
operator.
Each bit of the resulting integer is set if the corresponding bits of both input integers are set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise or for 16-bit signed integers. Usually accessed via the |||
operator.
Each bit of the resulting integer is set if at least one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise exclusive or for 16-bit signed integers. Usually accessed via the ^^^
operator.
Each bit of the resulting integer is set if exactly one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise left shift for 16-bit signed integers. Usually accessed via the <<<
operator.
Signed integers are interpreted as bitvectors according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Arithmetic right shift for 16-bit signed integers. Usually accessed via the <<<
operator.
The high bits are filled with the value of the most significant bit.
This function is overridden at runtime with an efficient implementation.
Equations
- a.shiftRight b = { toUInt16 := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod 16) } }
Instances For
Bitwise complement, also known as bitwise negation, for 16-bit signed integers. Usually accessed via
the ~~~
prefix operator.
Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so Int16.complement a = -(a + 1)
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.complement = { toUInt16 := { toBitVec := ~~~a.toBitVec } }
Instances For
Computes the absolute value of a 16-bit 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
.
This function is overridden at runtime with an efficient implementation.
Instances For
Decides whether two 16-bit signed integers are equal. Usually accessed via the DecidableEq Int16
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
Int16.decEq 123 123 = .isTrue rfl
(if ((-7) : Int16) = 7 then "yes" else "no") = "no"
show (7 : Int16) = 7 by decide
Instances For
Equations
- instComplementInt16 = { complement := Int16.complement }
Equations
- instShiftLeftInt16 = { shiftLeft := Int16.shiftLeft }
Equations
- instShiftRightInt16 = { shiftRight := Int16.shiftRight }
Decides whether one 16-bit signed integer is strictly less than another. Usually accessed via the
DecidableLT Int16
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : Int16) < 7 then "yes" else "no") = "yes"
(if (5 : Int16) < 5 then "yes" else "no") = "no"
show ¬((7 : Int16) < 7) by decide
Instances For
Decides whether one 16-bit signed integer is less than or equal to another. Usually accessed via the
DecidableLE Int16
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : Int16) ≤ 7 then "yes" else "no") = "yes"
(if (15 : Int16) ≤ 15 then "yes" else "no") = "yes"
(if (15 : Int16) ≤ 5 then "yes" else "no") = "no"
show (7 : Int16) ≤ 7 by decide
Instances For
Equations
- instDecidableLtInt16 a b = a.decLt b
Equations
- instDecidableLeInt16 a b = a.decLe b
The number of distinct values representable by Int32
, that is, 2^32 = 4294967296
.
Equations
- Int32.size = 4294967296
Instances For
Converts an arbitrary-precision integer to a 32-bit integer, wrapping on overflow or underflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int32.ofInt 48 = 48
Int32.ofInt (-129) = -129
Int32.ofInt 70000 = 70000
Int32.ofInt (-40000) = -40000
Int32.ofInt 2147483648 = -2147483648
Int32.ofInt (-2147483649) = 2147483647
Equations
- Int32.ofInt i = { toUInt32 := { toBitVec := BitVec.ofInt 32 i } }
Instances For
Converts a natural number to a 32-bit signed integer, wrapping around on overflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int32.ofNat 127 = 127
Int32.ofNat 32770 = 32770
Int32.ofNat 2_147_483_647 = 2_147_483_647
Int32.ofNat 2_147_483_648 = -2_147_483_648
Equations
- Int32.ofNat n = { toUInt32 := { toBitVec := BitVec.ofNat 32 n } }
Instances For
Converts an arbitrary-precision integer to a 32-bit integer, wrapping on overflow or underflow.
Examples:
Int.toInt32 48 = 48
Int.toInt32 (-129) = -129
Int.toInt32 70000 = 70000
Int.toInt32 (-40000) = -40000
Int.toInt32 2147483648 = -2147483648
Int.toInt32 (-2147483649) = 2147483647
Equations
Instances For
Converts a natural number to a 32-bit signed integer, wrapping around to negative numbers on overflow.
Examples:
Nat.toInt32 127 = 127
Nat.toInt32 32770 = 32770
Nat.toInt32 2_147_483_647 = 2_147_483_647
Nat.toInt32 2_147_483_648 = -2_147_483_648
Equations
Instances For
Converts a 32-bit signed integer to a natural number, mapping all negative numbers to 0
.
Use Int32.toBitVec
to obtain the two's complement representation.
Equations
- i.toNatClampNeg = i.toInt.toNat
Instances For
Converts a 32-bit signed integer to a natural number, mapping all negative numbers to 0
.
Use Int32.toBitVec
to obtain the two's complement representation.
Instances For
Obtains the Int32
whose 2's complement representation is the given BitVec 32
.
Equations
- Int32.ofBitVec b = { toUInt32 := { toBitVec := b } }
Instances For
Converts a 32-bit signed integer to an 8-bit signed integer by truncating its bitvector representation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt8 = { toUInt8 := { toBitVec := BitVec.signExtend 8 a.toBitVec } }
Instances For
Converts a 32-bit signed integer to an 16-bit signed integer by truncating its bitvector representation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt16 = { toUInt16 := { toBitVec := BitVec.signExtend 16 a.toBitVec } }
Instances For
Converts 8-bit signed integers to 32-bit signed integers that denote the same number.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt32 = { toUInt32 := { toBitVec := BitVec.signExtend 32 a.toBitVec } }
Instances For
Converts 8-bit signed integers to 32-bit signed integers that denote the same number.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt32 = { toUInt32 := { toBitVec := BitVec.signExtend 32 a.toBitVec } }
Instances For
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 largest number that Int32
can represent: 2^31 - 1 = 2147483647
.
Equations
- Int32.maxValue = 2147483647
Instances For
The smallest number that Int32
can represent: -2^31 = -2147483648
.
Equations
- Int32.minValue = -2147483648
Instances For
Constructs an Int32
from an Int
that is known to be in bounds.
Equations
- Int32.ofIntLE i _hl _hr = Int32.ofInt i
Instances For
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
Instances For
Adds two 32-bit signed integers, wrapping around on over- or underflow. Usually accessed via the
+
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Subtracts one 32-bit signed integer from another, wrapping around on over- or underflow. Usually
accessed via the -
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Multiplies two 32-bit signed integers, wrapping around on over- or underflow. Usually accessed via
the *
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Truncating division for 32-bit signed integers, rounding towards zero. Usually accessed via the /
operator.
Division by zero is defined to be zero.
This function is overridden at runtime with an efficient implementation.
Examples:
Int32.div 10 3 = 3
Int32.div 10 (-3) = (-3)
Int32.div (-10) (-3) = 3
Int32.div (-10) 3 = (-3)
Int32.div 10 0 = 0
Instances For
The modulo operator for 32-bit signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by Int32.div
. Usually accessed via the %
operator.
When the divisor is 0
, the result is the dividend rather than an error.
This function is overridden at runtime with an efficient implementation.
Examples:
Int32.mod 5 2 = 1
Int32.mod 5 (-2) = 1
Int32.mod (-5) 2 = (-1)
Int32.mod (-5) (-2) = (-1)
Int32.mod 4 2 = 0
Int32.mod 4 (-2) = 0
Int32.mod 4 0 = 4
Int32.mod (-4) 0 = (-4)
Instances For
Bitwise and for 32-bit signed integers. Usually accessed via the &&&
operator.
Each bit of the resulting integer is set if the corresponding bits of both input integers are set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise or for 32-bit signed integers. Usually accessed via the |||
operator.
Each bit of the resulting integer is set if at least one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise exclusive or for 32-bit signed integers. Usually accessed via the ^^^
operator.
Each bit of the resulting integer is set if exactly one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise left shift for 32-bit signed integers. Usually accessed via the <<<
operator.
Signed integers are interpreted as bitvectors according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Arithmetic right shift for 32-bit signed integers. Usually accessed via the <<<
operator.
The high bits are filled with the value of the most significant bit.
This function is overridden at runtime with an efficient implementation.
Equations
- a.shiftRight b = { toUInt32 := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod 32) } }
Instances For
Bitwise complement, also known as bitwise negation, for 32-bit signed integers. Usually accessed via
the ~~~
prefix operator.
Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so Int32.complement a = -(a + 1)
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.complement = { toUInt32 := { toBitVec := ~~~a.toBitVec } }
Instances For
Computes the absolute value of a 32-bit 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
.
This function is overridden at runtime with an efficient implementation.
Instances For
Decides whether two 32-bit signed integers are equal. Usually accessed via the DecidableEq Int32
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
Int32.decEq 123 123 = .isTrue rfl
(if ((-7) : Int32) = 7 then "yes" else "no") = "no"
show (7 : Int32) = 7 by decide
Instances For
Equations
- instComplementInt32 = { complement := Int32.complement }
Equations
- instShiftLeftInt32 = { shiftLeft := Int32.shiftLeft }
Equations
- instShiftRightInt32 = { shiftRight := Int32.shiftRight }
Decides whether one 32-bit signed integer is strictly less than another. Usually accessed via the
DecidableLT Int32
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : Int32) < 7 then "yes" else "no") = "yes"
(if (5 : Int32) < 5 then "yes" else "no") = "no"
show ¬((7 : Int32) < 7) by decide
Instances For
Decides whether one 32-bit signed integer is less than or equal to another. Usually accessed via the
DecidableLE Int32
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : Int32) ≤ 7 then "yes" else "no") = "yes"
(if (15 : Int32) ≤ 15 then "yes" else "no") = "yes"
(if (15 : Int32) ≤ 5 then "yes" else "no") = "no"
show (7 : Int32) ≤ 7 by decide
Instances For
Equations
- instDecidableLtInt32 a b = a.decLt b
Equations
- instDecidableLeInt32 a b = a.decLe b
The number of distinct values representable by Int64
, that is, 2^64 = 18446744073709551616
.
Equations
- Int64.size = 18446744073709551616
Instances For
Converts an arbitrary-precision integer to a 64-bit integer, wrapping on overflow or underflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int64.ofInt 48 = 48
Int64.ofInt (-40_000) = -40_000
Int64.ofInt 2_147_483_648 = 2_147_483_648
Int64.ofInt (-2_147_483_649) = -2_147_483_649
Int64.ofInt 9_223_372_036_854_775_808 = -9_223_372_036_854_775_808
Int64.ofInt (-9_223_372_036_854_775_809) = 9_223_372_036_854_775_807
Equations
- Int64.ofInt i = { toUInt64 := { toBitVec := BitVec.ofInt 64 i } }
Instances For
Converts a natural number to a 64-bit signed integer, wrapping around to negative numbers on overflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int64.ofNat 127 = 127
Int64.ofNat 2_147_483_648 = 2_147_483_648
Int64.ofNat 9_223_372_036_854_775_807 = 9_223_372_036_854_775_807
Int64.ofNat 9_223_372_036_854_775_808 = -9_223_372_036_854_775_808
Int64.ofNat 18_446_744_073_709_551_618 = 0
Equations
- Int64.ofNat n = { toUInt64 := { toBitVec := BitVec.ofNat 64 n } }
Instances For
Converts an arbitrary-precision integer to a 64-bit integer, wrapping on overflow or underflow.
This function is overridden at runtime with an efficient implementation.
Examples:
Int.toInt64 48 = 48
Int.toInt64 (-40_000) = -40_000
Int.toInt64 2_147_483_648 = 2_147_483_648
Int.toInt64 (-2_147_483_649) = -2_147_483_649
Int.toInt64 9_223_372_036_854_775_808 = -9_223_372_036_854_775_808
Int.toInt64 (-9_223_372_036_854_775_809) = 9_223_372_036_854_775_807
Equations
Instances For
Converts a natural number to a 64-bit signed integer, wrapping around to negative numbers on overflow.
Examples:
Nat.toInt64 127 = 127
Nat.toInt64 2_147_483_648 = 2_147_483_648
Nat.toInt64 9_223_372_036_854_775_807 = 9_223_372_036_854_775_807
Nat.toInt64 9_223_372_036_854_775_808 = -9_223_372_036_854_775_808
Nat.toInt64 18_446_744_073_709_551_618 = 0
Equations
Instances For
Converts a 64-bit signed integer to a natural number, mapping all negative numbers to 0
.
Use Int64.toBitVec
to obtain the two's complement representation.
Equations
- i.toNatClampNeg = i.toInt.toNat
Instances For
Converts a 64-bit signed integer to a natural number, mapping all negative numbers to 0
.
Use Int64.toBitVec
to obtain the two's complement representation.
Instances For
Obtains the Int64
whose 2's complement representation is the given BitVec 64
.
Equations
- Int64.ofBitVec b = { toUInt64 := { toBitVec := b } }
Instances For
Converts a 64-bit signed integer to an 8-bit signed integer by truncating its bitvector representation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt8 = { toUInt8 := { toBitVec := BitVec.signExtend 8 a.toBitVec } }
Instances For
Converts a 64-bit signed integer to a 16-bit signed integer by truncating its bitvector representation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt16 = { toUInt16 := { toBitVec := BitVec.signExtend 16 a.toBitVec } }
Instances For
Converts a 64-bit signed integer to a 32-bit signed integer by truncating its bitvector representation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt32 = { toUInt32 := { toBitVec := BitVec.signExtend 32 a.toBitVec } }
Instances For
Converts 8-bit signed integers to 64-bit signed integers that denote the same number.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt64 = { toUInt64 := { toBitVec := BitVec.signExtend 64 a.toBitVec } }
Instances For
Converts 16-bit signed integers to 64-bit signed integers that denote the same number.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt64 = { toUInt64 := { toBitVec := BitVec.signExtend 64 a.toBitVec } }
Instances For
Converts 32-bit signed integers to 64-bit signed integers that denote the same number.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt64 = { toUInt64 := { toBitVec := BitVec.signExtend 64 a.toBitVec } }
Instances For
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 largest number that Int64
can represent: 2^63 - 1 = 9223372036854775807
.
Equations
- Int64.maxValue = 9223372036854775807
Instances For
The smallest number that Int64
can represent: -2^63 = -9223372036854775808
.
Equations
- Int64.minValue = -9223372036854775808
Instances For
Constructs an Int64
from an Int
that is known to be in bounds.
Equations
- Int64.ofIntLE i _hl _hr = Int64.ofInt i
Instances For
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
Instances For
Adds two 64-bit signed integers, wrapping around on over- or underflow. Usually accessed via the
+
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Subtracts one 64-bit signed integer from another, wrapping around on over- or underflow. Usually
accessed via the -
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Multiplies two 64-bit signed integers, wrapping around on over- or underflow. Usually accessed via
the *
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Truncating division for 64-bit signed integers, rounding towards zero. Usually accessed via the /
operator.
Division by zero is defined to be zero.
This function is overridden at runtime with an efficient implementation.
Examples:
Int64.div 10 3 = 3
Int64.div 10 (-3) = (-3)
Int64.div (-10) (-3) = 3
Int64.div (-10) 3 = (-3)
Int64.div 10 0 = 0
Instances For
The modulo operator for 64-bit signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by Int64.div
. Usually accessed via the %
operator.
When the divisor is 0
, the result is the dividend rather than an error.
This function is overridden at runtime with an efficient implementation.
Examples:
Int64.mod 5 2 = 1
Int64.mod 5 (-2) = 1
Int64.mod (-5) 2 = (-1)
Int64.mod (-5) (-2) = (-1)
Int64.mod 4 2 = 0
Int64.mod 4 (-2) = 0
Int64.mod 4 0 = 4
Int64.mod (-4) 0 = (-4)
Instances For
Bitwise and for 64-bit signed integers. Usually accessed via the &&&
operator.
Each bit of the resulting integer is set if the corresponding bits of both input integers are set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise or for 64-bit signed integers. Usually accessed via the |||
operator.
Each bit of the resulting integer is set if at least one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise exclusive or for 64-bit signed integers. Usually accessed via the ^^^
operator.
Each bit of the resulting integer is set if exactly one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise left shift for 64-bit signed integers. Usually accessed via the <<<
operator.
Signed integers are interpreted as bitvectors according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Arithmetic right shift for 64-bit signed integers. Usually accessed via the <<<
operator.
The high bits are filled with the value of the most significant bit.
This function is overridden at runtime with an efficient implementation.
Equations
- a.shiftRight b = { toUInt64 := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod 64) } }
Instances For
Bitwise complement, also known as bitwise negation, for 64-bit signed integers. Usually accessed via
the ~~~
prefix operator.
Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so Int64.complement a = -(a + 1)
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.complement = { toUInt64 := { toBitVec := ~~~a.toBitVec } }
Instances For
Computes the absolute value of a 64-bit 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
.
This function is overridden at runtime with an efficient implementation.
Instances For
Decides whether two 64-bit signed integers are equal. Usually accessed via the DecidableEq Int64
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
Int64.decEq 123 123 = .isTrue rfl
(if ((-7) : Int64) = 7 then "yes" else "no") = "no"
show (7 : Int64) = 7 by decide
Instances For
Equations
- instComplementInt64 = { complement := Int64.complement }
Equations
- instShiftLeftInt64 = { shiftLeft := Int64.shiftLeft }
Equations
- instShiftRightInt64 = { shiftRight := Int64.shiftRight }
Decides whether one 8-bit signed integer is strictly less than another. Usually accessed via the
DecidableLT Int64
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : Int64) < 7 then "yes" else "no") = "yes"
(if (5 : Int64) < 5 then "yes" else "no") = "no"
show ¬((7 : Int64) < 7) by decide
Instances For
Decides whether one 8-bit signed integer is less than or equal to another. Usually accessed via the
DecidableLE Int64
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : Int64) ≤ 7 then "yes" else "no") = "yes"
(if (15 : Int64) ≤ 15 then "yes" else "no") = "yes"
(if (15 : Int64) ≤ 5 then "yes" else "no") = "no"
show (7 : Int64) ≤ 7 by decide
Instances For
Equations
- instDecidableLtInt64 a b = a.decLt b
Equations
- instDecidableLeInt64 a b = a.decLe b
The number of distinct values representable by ISize
, that is, 2^System.Platform.numBits
.
Equations
Instances For
Converts an arbitrary-precision integer to a word-sized signed integer, wrapping around on over- or underflow.
This function is overridden at runtime with an efficient implementation.
Equations
- ISize.ofInt i = { toUSize := { toBitVec := BitVec.ofInt System.Platform.numBits i } }
Instances For
Converts an arbitrary-precision natural number to a word-sized signed integer, wrapping around on overflow.
This function is overridden at runtime with an efficient implementation.
Equations
- ISize.ofNat n = { toUSize := { toBitVec := BitVec.ofNat System.Platform.numBits n } }
Instances For
Converts an arbitrary-precision integer to a word-sized signed integer, wrapping around on over- or underflow.
This function is overridden at runtime with an efficient implementation.
Equations
Instances For
Converts an arbitrary-precision natural number to a word-sized signed integer, wrapping around on overflow.
This function is overridden at runtime with an efficient implementation.
Equations
Instances For
Converts a word-sized signed integer to a natural number, mapping all negative numbers to 0
.
Use ISize.toBitVec
to obtain the two's complement representation.
Equations
- i.toNatClampNeg = i.toInt.toNat
Instances For
Converts a word-sized signed integer to a natural number, mapping all negative numbers to 0
.
Use ISize.toBitVec
to obtain the two's complement representation.
Instances For
Obtains the ISize
whose 2's complement representation is the given BitVec
.
Equations
- ISize.ofBitVec b = { toUSize := { toBitVec := b } }
Instances For
Converts a word-sized signed integer to an 8-bit signed integer by truncating its bitvector representation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt8 = { toUInt8 := { toBitVec := BitVec.signExtend 8 a.toBitVec } }
Instances For
Converts a word-sized integer to a 16-bit integer by truncating its bitvector representation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt16 = { toUInt16 := { toBitVec := BitVec.signExtend 16 a.toBitVec } }
Instances For
Converts a word-sized signed integer to a 32-bit signed integer.
On 32-bit platforms, this conversion is lossless. On 64-bit platforms, the integer's bitvector representation is truncated to 32 bits. This function is overridden at runtime with an efficient implementation.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt32 = { toUInt32 := { toBitVec := BitVec.signExtend 32 a.toBitVec } }
Instances For
Converts word-sized signed integers to 64-bit signed integers that denote the same number. This
conversion is lossless, because ISize
is either Int32
or Int64
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toInt64 = { toUInt64 := { toBitVec := BitVec.signExtend 64 a.toBitVec } }
Instances For
Converts 8-bit signed integers to word-sized signed integers that denote the same number. This
conversion is lossless, because ISize
is either Int32
or Int64
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toISize = { toUSize := { toBitVec := BitVec.signExtend System.Platform.numBits a.toBitVec } }
Instances For
Converts 16-bit signed integers to word-sized signed integers that denote the same number. This conversion is lossless, because
ISize
is either Int32
or Int64
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toISize = { toUSize := { toBitVec := BitVec.signExtend System.Platform.numBits a.toBitVec } }
Instances For
Converts 32-bit signed integers to word-sized signed integers that denote the same number. This
conversion is lossless, because ISize
is either Int32
or Int64
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toISize = { toUSize := { toBitVec := BitVec.signExtend System.Platform.numBits a.toBitVec } }
Instances For
Converts 64-bit signed integers to word-sized signed integers, truncating the bitvector representation on 32-bit platforms. This conversion is lossless on 64-bit platforms.
This function is overridden at runtime with an efficient implementation.
Equations
- a.toISize = { toUSize := { toBitVec := BitVec.signExtend System.Platform.numBits a.toBitVec } }
Instances For
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 largest number that ISize
can represent: 2^(System.Platform.numBits - 1) - 1
.
Equations
- ISize.maxValue = ISize.ofInt (2 ^ (System.Platform.numBits - 1) - 1)
Instances For
The smallest number that ISize
can represent: -2^(System.Platform.numBits - 1)
.
Equations
- ISize.minValue = ISize.ofInt (-2 ^ (System.Platform.numBits - 1))
Instances For
Constructs an ISize
from an Int
that is known to be in bounds.
Equations
- ISize.ofIntLE i _hl _hr = ISize.ofInt i
Instances For
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
Instances For
Adds two word-sized signed integers, wrapping around on over- or underflow. Usually accessed via
the +
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Subtracts one word-sized signed integer from another, wrapping around on over- or underflow. Usually
accessed via the -
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Multiplies two word-sized signed integers, wrapping around on over- or underflow. Usually accessed
via the *
operator.
This function is overridden at runtime with an efficient implementation.
Instances For
Truncating division for word-sized signed integers, rounding towards zero. Usually accessed via the
/
operator.
Division by zero is defined to be zero.
This function is overridden at runtime with an efficient implementation.
Examples:
ISize.div 10 3 = 3
ISize.div 10 (-3) = (-3)
ISize.div (-10) (-3) = 3
ISize.div (-10) 3 = (-3)
ISize.div 10 0 = 0
Instances For
The modulo operator for word-sized signed integers, which computes the remainder when dividing one
integer by another with the T-rounding convention used by ISize.div
. Usually accessed via the %
operator.
When the divisor is 0
, the result is the dividend rather than an error.
This function is overridden at runtime with an efficient implementation.
Examples:
ISize.mod 5 2 = 1
ISize.mod 5 (-2) = 1
ISize.mod (-5) 2 = (-1)
ISize.mod (-5) (-2) = (-1)
ISize.mod 4 2 = 0
ISize.mod 4 (-2) = 0
ISize.mod 4 0 = 4
ISize.mod (-4) 0 = (-4)
Instances For
Bitwise and for word-sized signed integers. Usually accessed via the &&&
operator.
Each bit of the resulting integer is set if the corresponding bits of both input integers are set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise or for word-sized signed integers. Usually accessed via the |||
operator.
Each bit of the resulting integer is set if at least one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise exclusive or for word-sized signed integers. Usually accessed via the ^^^
operator.
Each bit of the resulting integer is set if exactly one of the corresponding bits of the input integers is set, according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Instances For
Bitwise left shift for word-sized signed integers. Usually accessed via the <<<
operator.
Signed integers are interpreted as bitvectors according to the two's complement representation.
This function is overridden at runtime with an efficient implementation.
Equations
Instances For
Arithmetic right shift for word-sized signed integers. Usually accessed via the <<<
operator.
The high bits are filled with the value of the most significant bit.
This function is overridden at runtime with an efficient implementation.
Equations
- a.shiftRight b = { toUSize := { toBitVec := a.toBitVec.sshiftRight' (b.toBitVec.smod ↑System.Platform.numBits) } }
Instances For
Bitwise complement, also known as bitwise negation, for word-sized signed integers. Usually accessed
via the ~~~
prefix operator.
Each bit of the resulting integer is the opposite of the corresponding bit of the input integer.
Integers use the two's complement representation, so ISize.complement a = -(a + 1)
.
This function is overridden at runtime with an efficient implementation.
Equations
- a.complement = { toUSize := { toBitVec := ~~~a.toBitVec } }
Instances For
Computes the absolute value of a word-sized 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
.
This function is overridden at runtime with an efficient implementation.
Instances For
Decides whether two word-sized signed integers are equal. Usually accessed via the
DecidableEq ISize
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
ISize.decEq 123 123 = .isTrue rfl
(if ((-7) : ISize) = 7 then "yes" else "no") = "no"
show (7 : ISize) = 7 by decide
Instances For
Equations
- instComplementISize = { complement := ISize.complement }
Equations
- instShiftLeftISize = { shiftLeft := ISize.shiftLeft }
Equations
- instShiftRightISize = { shiftRight := ISize.shiftRight }
Decides whether one word-sized signed integer is strictly less than another. Usually accessed via the
DecidableLT ISize
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : ISize) < 7 then "yes" else "no") = "yes"
(if (5 : ISize) < 5 then "yes" else "no") = "no"
show ¬((7 : ISize) < 7) by decide
Instances For
Decides whether one word-sized signed integer is less than or equal to another. Usually accessed via
the DecidableLE ISize
instance.
This function is overridden at runtime with an efficient implementation.
Examples:
(if ((-7) : ISize) ≤ 7 then "yes" else "no") = "yes"
(if (15 : ISize) ≤ 15 then "yes" else "no") = "yes"
(if (15 : ISize) ≤ 5 then "yes" else "no") = "no"
show (7 : ISize) ≤ 7 by decide
Instances For
Equations
- instDecidableLtISize a b = a.decLt b
Equations
- instDecidableLeISize a b = a.decLe b