Unavailable. Nobody can download this version any more, with elm or with the Lamdera compiler: github.com/malaire/elm-uint64 is gone (deleted or private); Software Heritage has tag 1.0.0 at 236cdeb39bed, not fetched yet (this run's --swh-calls were used up); no fork with tag 1.0.0 found (2 same-name repos checked); no cached copy. Use another version.
64-bit unsigned integer using wrapping overflow.
Maximum possible UInt64 value.
2^64 - 1 = 18446744073709551615 = 0xFFFFFFFFFFFFFFFF
UInt64.maxValue
|> UInt64.toString
--> "18446744073709551615"maxSafe as Float
Maximum UInt64 value that can be represented exactly as a Float.
2^64 - 2048 = 18446744073709549568 = 0xFFFFFFFFFFFFF800
Note: Float can't represent exactly all integers above maxSafe.
For example integers maxFloat+ 1 <= x <=maxValue can't be represented exactly as Float,
making this the maximum UInt64 value that can.
maxFloat as Float
Every Int or Float argument of every UInt64 function is limited
by one of the following three functions (or equivalent code):
Int and valid value is 0 <= x < 2^n, n <= 32limitSmallIntn value.Int and valid value can be 2^32 or abovelimitLargeIntvalue.Float and valid value is 0 <= x <= maxlimitFloatmax value.IntInt arguments are expected to be integers
and are not checked for non-integer values like NaN, -Infinity, +Infinity or 12.34.
Behavior of any UInt64 function is undefined if Int argument is not an integer.
IntBehavior of Int for values above 2^31 - 1 is undefined in Elm.
As of Elm 0.19.1, using Int as function parameter or return value works for full safe integer range
up to maxSafe, but this could change in the future.
Note: This affects also limitSmallInt with n = 32.
Limit Int to 0 <= value < 2 ^ bitSize.
bitSize: 1 <= bitSize <= 32value: value to limitSee argument handling.
Algorithm:
2 ^ bitSize - 1.-- `1234` limited to 6 bits, i.e. `0 <= x <= 63`
UInt64.limitSmallInt 6 1234
--> 18
-- `-1` limited to 8 bits, i.e. `0 <= x <= 255`
UInt64.limitSmallInt 8 -1
--> 0xFF
-- `-1` limited to 32 bits
UInt64.limitSmallInt 32 -1
--> 0xFFFFFFFFLimit Int to 0 <= value <=maxSafe.
See argument handling.
Algorithm:
-- negative value is replaced with zero
UInt64.limitLargeInt -1
--> 0
-- value above `maxSafe` is replaced with `maxSafe`
UInt64.limitLargeInt 9007199254740992
--> 9007199254740991Limit Float to 0 <= value <= max.
max: maximum allowed value, max <=maxFloatvalue: value to limitSee argument handling.
Algorithm:
NaN, use 0 instead.0 instead.max, use max instead.-- `-1` limited to 12 decimal digits
UInt64.limitFloat 999999999999 -1
--> 0
-- `1e20` limited to 12 decimal digits
UInt64.limitFloat 999999999999 1e20
--> 999999999999
-- `1e20` limited to `0 <= value <= maxFloat`
UInt64.limitFloat UInt64.maxFloatAsFloat 1.0e20
--> 18446744073709549568.0Convert Int to UInt64.
value: 0 <= x <=maxSafeSee argument handling.
UInt64.fromInt 123
|> UInt64.toString
--> "123"Convert Float to UInt64, rounding down.
value: 0 <= x <=maxFloat**) If value is above maxValue, return maxValue.
See argument handling.
Conversion is exact for all possible Float integer values from 0 to maxFloat.
However because Float can't represent all integers above maxSafe,
it can sometimes seem like there is an error.
In the following example value 11222333444555666777.0 can't be represented exactly as a Float.
Nearest value that can be represented exactly as a Float is 11222333444555667456.0,
and that is what UInt64.floor gets as its argument.
This argument is then converted exactly to UInt64.
UInt64.floor 11222333444555666777.0
|> UInt64.toString
--> "11222333444555667456"fromDecimal12s can be used instead
to convert decimal literals above maxSafe to UInt64:
UInt64.fromDecimal12s 11222333 444555666777
|> UInt64.toString
--> "11222333444555666777"Convert UInt64 to Float.
Conversion is exact for any value from 0 to maxSafe,
but above maxSafe value is rounded if it can't be represented exactly as Float.
9007199254740993 can't be represented exactly as Float,
so it's rounded to 9007199254740992.
UInt64.fromDecimal12s 9007 199254740993
|> UInt64.toFloat
--> 9007199254740992Convert 64-bit unsigned integer represented as two 32-bit unsigned integers to UInt64.
high: 32-bit unsigned integer for bits 32 - 63low: 32-bit unsigned integer for bits 0 - 31See argument handling.
UInt64.fromInt32s 0x11223344 0xAABBCCDD
|> UInt64.toHexString
--> "11223344AABBCCDD"
UInt64.fromInt32s 1 2
|> UInt64.toHexString
--> "0000000100000002"Convert 64-bit unsigned integer represented as three 24-bit unsigned integers to UInt64.
This is the internal format of UInt64
and so fromInt24s is the fastest way to create UInt64 value.
high: 16-bit unsigned integer for bits 48 - 63mid: 24-bit unsigned integer for bits 24 - 47low: 24-bit unsigned integer for bits 0 - 23See argument handling.
UInt64.fromInt24s 0x1122 0x334455 0x667788
|> UInt64.toHexString
--> "1122334455667788"
UInt64.fromInt24s 1 2 3
|> UInt64.toHexString
--> "0001000002000003"Convert UInt64 to 64-bit unsigned integer represented as three 24-bit unsigned integers.
This is the internal format of UInt64
and so toInt24s is the fastest way to extract value out of UInt64.
high: 16-bit unsigned integer for bits 48 - 63mid: 24-bit unsigned integer for bits 24 - 47low: 24-bit unsigned integer for bits 0 - 23UInt64.fromInt32s 0x11223344 0xAABBCCDD
|> UInt64.toInt24s
--> ( 0x1122, 0x3344AA, 0xBBCCDD )Convert 64-bit unsigned integer represented as two 12-decimal-digit unsigned integers to UInt64.
high: 8 highest digits, 0 <= high <= 18446745*low: 12 lowest digits, 0 <= low <= 999999999999*) If high is 18446745, return maxValue.
See argument handling.
UInt64.fromDecimal12s 111222 333444555666
|> UInt64.toString
--> "111222333444555666"
UInt64.fromDecimal12s 1 2
|> UInt64.toString
--> "1000000000002"Convert list of bytes in big-endian order to UInt64.
byte: 0 <= x <= 255See argument handling.
UInt64.fromBigEndianBytes [ 0xAB, 0, 0xCD ]
|> UInt64.toHexString
--> "0000000000AB00CD"
List.range 0x01 0x0F
|> UInt64.fromBigEndianBytes
|> UInt64.toHexString
--> "08090A0B0C0D0E0F"Convert UInt64 to list of 8 bytes in big-endian order.
UInt64.fromInt 0xABCDEF
|> UInt64.toBigEndianBytes
--> [ 0, 0, 0, 0, 0, 0xAB, 0xCD, 0xEF ]Convert UInt64 to decimal String.
UInt64.fromInt 0xFFFFFF
|> UInt64.toString
--> "16777215"Convert UInt64 to uppercase hexadecimal String of 16 characters.
UInt64.floor 1e15
|> UInt64.toHexString
--> "00038D7EA4C68000"
UInt64.zero
|> UInt64.toHexString
--> "0000000000000000"Addition with wrapping overflow.
-- `123 + 456`
UInt64.add (UInt64.fromInt 123) (UInt64.fromInt 456)
|> UInt64.toString
--> "579"
-- `maxValue + 100`
UInt64.add UInt64.maxValue (UInt64.fromInt 100)
|> UInt64.toString
--> "99"Subtraction with wrapping overflow.
-- `456 - 123`
UInt64.sub (UInt64.fromInt 456) (UInt64.fromInt 123)
|> UInt64.toString
--> "333"
-- `0 - 0xFF`
UInt64.sub UInt64.zero (UInt64.fromInt 0xFF)
|> UInt64.toHexString
--> "FFFFFFFFFFFFFF01"Multiplication with wrapping overflow.
-- `1e9 * 1e9`
UInt64.mul (UInt64.floor 1e9) (UInt64.floor 1e9)
|> UInt64.toString
--> "1000000000000000000"
-- `(1e10 * 1e10) % 2^64`
UInt64.mul (UInt64.floor 1e10) (UInt64.floor 1e10)
|> UInt64.toString
--> "7766279631452241920"Power aka exponentiation. 0 ^ 0 = 1
-- `3 ^ 7`
UInt64.pow (UInt64.fromInt 3) (UInt64.fromInt 7)
|> UInt64.toString
--> "2187"
-- `10 ^ 19`
UInt64.pow (UInt64.fromInt 10) (UInt64.fromInt 19)
|> UInt64.toString
--> "10000000000000000000"
-- `(3 ^ 10000000000000000000) % 2^64`
UInt64.pow (UInt64.fromInt 10) (UInt64.fromInt 19)
|> UInt64.pow (UInt64.fromInt 3)
|> UInt64.toString
--> "12038004833498693633"Note: Uses fast algorithms: Bases 0-2 are special-cased, exponents 0-16 use addition-chain exponentiation🢅 and exponents over 16 use exponentiation by squaring🢅.
Increment by one with wrapping overflow.
-- `42 + 1`
UInt64.increment (UInt64.fromInt 42)
|> UInt64.toString
--> "43"
-- `maxValue + 1`
UInt64.increment UInt64.maxValue
|> UInt64.toString
--> "0"Decrement by one with wrapping overflow.
-- `42 - 1`
UInt64.decrement (UInt64.fromInt 42)
|> UInt64.toString
--> "41"
-- `0 - 1`
UInt64.decrement UInt64.zero
|> UInt64.toHexString
--> "FFFFFFFFFFFFFFFF"Integer division with modulo.
zero, return ( zero, zero ).UInt64.divMod
(UInt64.fromInt 123456)
(UInt64.fromInt 1000)
|> Tuple.mapBoth UInt64.toFloat UInt64.toFloat
--> ( 123, 456 )
-- ( 0xFFFFFFFFFFFFFFFF / 1e10, 0xFFFFFFFFFFFFFFFF % 1e10 )
UInt64.divMod UInt64.maxValue (UInt64.floor 1e10)
|> Tuple.mapBoth UInt64.toFloat UInt64.toFloat
--> ( 1844674407, 3709551615 )Note: I would prefer to cause runtime exception on division-by-zero,
but that can't be tested, so I'll settle for returning ( zero, zero ) which can be tested.
Bitwise AND.
UInt64.and
(UInt64.fromInt32s 0x11223344 0xAABBCCDD)
(UInt64.fromInt32s 0x0000FFFF 0xFFFF0000)
|> UInt64.toHexString
--> "00003344AABB0000"Bitwise OR.
UInt64.or
(UInt64.fromInt32s 0x11223344 0xAABBCCDD)
(UInt64.fromInt32s 0x0000FFFF 0xFFFF0000)
|> UInt64.toHexString
--> "1122FFFFFFFFCCDD"Bitwise XOR.
UInt64.xor
(UInt64.fromInt32s 0x11223344 0xAABBCCDD)
(UInt64.fromInt32s 0x0000FFFF 0xFFFF0000)
|> UInt64.toHexString
--> "1122CCBB5544CCDD"Bitwise complement, aka bitwise NOT, aka one's complement.
UInt64.fromInt32s 0x11223344 0xAABBCCDD
|> UInt64.complement
|> UInt64.toHexString
--> "EEDDCCBB55443322"Bitwise shift left, filling with zeroes from right.
shift: 0 <= x <= 63See argument handling.
UInt64.fromInt32s 0x11223344 0xAABBCCDD
|> UInt64.shiftLeftBy 20
|> UInt64.toHexString
--> "344AABBCCDD00000"Bitwise shift right, filling with zeroes from left.
shift: 0 <= x <= 63See argument handling.
UInt64.fromInt32s 0x11223344 0xAABBCCDD
|> UInt64.shiftRightZfBy 20
|> UInt64.toHexString
--> "0000011223344AAB"Bitwise rotate left.
shift: 0 <= x <= 63See argument handling.
UInt64.fromInt32s 0x11223344 0xAABBCCDD
|> UInt64.rotateLeftBy 20
|> UInt64.toHexString
--> "344AABBCCDD11223"Bitwise rotate right.
shift: 0 <= x <= 63See argument handling.
UInt64.fromInt32s 0x11223344 0xAABBCCDD
|> UInt64.rotateRightBy 20
|> UInt64.toHexString
--> "BCCDD11223344AAB"Return a bit.
bitNumber: 0 <= x <= 63, least significant bit is 0See argument handling.
UInt64.one
|> UInt64.getBit 0
--> 1Set a bit to given value.
bitNumber: 0 <= x <= 63, least significant bit is 0bitValue: new value, either 0 or 1See argument handling.
UInt64.zero
|> UInt64.setBit 30 1
|> UInt64.toHexString
--> "0000000040000000"Compare two UInt64:s.
UInt64.compare UInt64.zero UInt64.one
--> LTReturn True if argument is safe integer.
A safe integer is an integer that
Float andFloat.Unsigned integers from 0 to maxSafe are safe integers.
For example 2^53 is not a safe integer.
While it can be represented exactly as Float,
there exists another integer 2^53 + 1 which is rounded to 2^53:
-- 2^53 + 1 (9007199254740993) is rounded to
-- 2^53 (9007199254740992) when converted to Float
UInt64.fromDecimal12s 9007 199254740993
|> UInt64.toFloat
--> 9007199254740992
UInt64.fromDecimal12s 9007 199254740993
|> UInt64.isSafe
--> FalseThis happens because 2^53 + 1 can't be represented exactly as Float,
so it is rounded to another integer.
Extra functions which can be useful for some use cases, e.g. benchmarking and testing.
These are not intended to be useful generally.
Fast but complex algorithm for integer division with modulo.
zero, return Ok ( zero, zero ).Err error.divModSlow.You should usually use divMod instead because it will use
even faster algorithms when dividend < 2^53 or divisor < 2^29,
and will fall back to divModFast otherwise.
So divModFast is faster than divMod only when
dividend >= 2^53 && divisor >= 2^29.
Simple but slow long division🢅 algorithm for integer division with modulo.
zero, return ( zero, zero ).Intended use cases:
divModFast,
in case it returns Err. Which should never happen.
64-bit unsigned integer.
UInt64is represented internally as three unsigned integers:high: 16-bit unsigned integer for bits 48 - 63mid: 24-bit unsigned integer for bits 24 - 47low: 24-bit unsigned integer for bits 0 - 23