#i64
Signed 64-bit integers, the I64 type.
An I64 holds a value from -9223372036854775808 to
9223372036854775807. Its arithmetic wraps in two's complement: +, -
and * give the result modulo 2^64, so 9223372036854775807 + 1 is
-9223372036854775808. / and % truncate toward zero, as C does, so
-7 / 2 is -3 and -7 % 2 is -1; minBound / -1 wraps to minBound,
and a zero divisor panics as it does for Int. negate and abs wrap the
same way, so both give minBound for minBound.
An integer literal in I64 position may be as large as the type holds,
including beyond Int's range, as in -9223372036854775808. Every Int
fits, so fromInt never panics and needs no checked or truncating
counterpart.
Int holds 63 bits, so the way back narrows: toInt answers None for a
value outside -4611686018427387904 to 4611686018427387903.
fromU8, fromU16, fromU32 and fromI32 widen a narrower value.
fromBits and toBits convert to and from U64 by keeping the 64 bits and
changing how they are read, so the bit operations the u64 module has and
this one does not (rotations, bit counts, bytes, hexadecimal) are reached
through them.
bitAnd, bitOr, bitXor, bitNot, shiftLeft and shiftRight have the
same names as the prelude's Int operations. Import the module qualified,
as import i64 as I64, and write I64.shiftLeft. shiftRight is
arithmetic: the vacated bits copy the sign.
I64 values compare, hash, and render in decimal like Int.
#Conversions
#toInt
toInt : I64 -> Option Int
toInt xThe value as an Int, or None when it is outside -4611686018427387904
to 4611686018427387903.
> toInt (-5)
Some (-5)
> toInt 9223372036854775807
None#fromU8
fromU8 : U8 -> I64
fromU8 xA U8 as an I64, the same number.
> toInt (fromU8 (255 : U8))
Some 255#fromU16
fromU16 : U16 -> I64
fromU16 xA U16 as an I64, the same number.
> toInt (fromU16 (65535 : U16))
Some 65535#fromU32
fromU32 : U32 -> I64
fromU32 xA U32 as an I64, the same number.
> toInt (fromU32 (4294967295 : U32))
Some 4294967295#fromI32
fromI32 : I32 -> I64
fromI32 xAn I32 as an I64, the same number.
> toInt (fromI32 (-2147483648 : I32))
Some (-2147483648)#fromBits
fromBits : U64 -> I64
fromBits xA U64's 64 bits read in two's complement: the same bits, a different
number when the top bit is set.
> toInt (fromBits (0xFFFFFFFFFFFFFFFF : U64))
Some (-1)#toBits
toBits : I64 -> U64
toBits xThe value's 64 bits in two's complement, as a U64.
> toBits (-1) == 0xFFFFFFFFFFFFFFFF
True#Bit operations
#bitAnd
bitAnd : I64 -> I64 -> I64
bitAnd a bThe bitwise and of two values.
> toInt (bitAnd (-4) 7)
Some 4#bitOr
bitOr : I64 -> I64 -> I64
bitOr a bThe bitwise or of two values.
> toInt (bitOr 12 10)
Some 14#bitXor
bitXor : I64 -> I64 -> I64
bitXor a bThe bitwise exclusive or of two values.
> toInt (bitXor (-1) 5)
Some (-6)#bitNot
bitNot : I64 -> I64
bitNot xEvery bit of the value inverted, so bitNot x is -x - 1.
> toInt (bitNot 0)
Some (-1)#shiftLeft
shiftLeft : I64 -> Int -> I64
shiftLeft x kThe value shifted left by a number of bits, the vacated bits zero.
Bits shifted past bit 63 are discarded, the sign bit included, and a shift
of 64 or more gives 0. A negative shift panics.
> shiftLeft 1 63 == minBound
True
> toInt (shiftLeft 1 64)
Some 0#shiftRight
shiftRight : I64 -> Int -> I64
shiftRight x kThe value shifted right by a number of bits, the vacated bits copies of the sign bit, so a negative value stays negative.
A shift of 64 or more gives 0, or -1 for a negative value. A negative
shift panics.
> toInt (shiftRight (-16) 2)
Some (-4)
> toInt (shiftRight minBound 70)
Some (-1)#Instances
#Instances
I64:Eq,Ord,Num,Bounded,Hashable,Display,Debug
#Num I64
impl Num I64Arithmetic modulo 2^64 in two's complement. fromInt never panics, since
every Int fits. abs and negate of minBound are minBound.