std/core/int▲toc

Standard integer intstd/core/types/int: V functions.

These are arbitrary precision signed integer with an efficient runtime representation. For more details, see:

“What About the Integer Numbers? ”Fast Arithmetic with Tagged Integers – A Plea for Hardware Support“ Daan Leijen, Technical report MSR-TR-2022-17, 2022-07-11, v1.0. Presented at the ML workshop 2022.” https://​www.​microsoft.​com/​en-​us/​research/​uploads/​prod/​2022/​07/​int.​pdf.

fun int16/int( i : int16std/core/types/int16: V ) : intstd/core/types/int: V

Convert an int16std/core/types/int16: V to an intstd/core/types/int: V.

fun int8/int( i : int8std/core/types/int8: V ) : intstd/core/types/int: V

Convert an int8std/core/types/int8: V to an intstd/core/types/int: V.

fun int8/uint( i : int8std/core/types/int8: V ) : intstd/core/types/int: V

Convert an int8std/core/types/int8: V to an intstd/core/types/int: V but interpret the int8std/core/types/int8: V as an unsigned 8-bit value between 0 and 255.

fun intptr_t/int( i : intptr_tstd/core/types/intptr_t: V ) : intstd/core/types/int: V

Convert an intptr_tstd/core/types/intptr_t: V to an intstd/core/types/int: V.

fun ssize_t/int( i : ssize_tstd/core/types/ssize_t: V ) : intstd/core/types/int: V

Convert an ssize_tstd/core/types/ssize_t: V to an intstd/core/types/int: V.

fun (!=)( ^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Are two integers not equal?

fun (%)( intstd/core/types/int: V, intstd/core/types/int: V ) : intstd/core/types/int: V

Euclidean modulus of two integers; always a non-negative number. See also divmodstd/core/int/divmod: (x : int, y : int) -> (int, int).

fun (*)( intstd/core/types/int: V, intstd/core/types/int: V ) : intstd/core/types/int: V

Multiply two integers.

fun (+)( x : intstd/core/types/int: V, y : intstd/core/types/int: V ) : intstd/core/types/int: V

Add two integers.

fun (-)( x : intstd/core/types/int: V, y : intstd/core/types/int: V ) : intstd/core/types/int: V

Substract two integers.

fun (/)( x : intstd/core/types/int: V, y : intstd/core/types/int: V ) : intstd/core/types/int: V

Euclidean-0 division of two integers. See also divmodstd/core/int/divmod: (x : int, y : int) -> (int, int).

fun (<)( ^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is the first integer smaller than the second?

fun (<=)( ^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is the first integer smaller or equal to the second?

fun (==)( ^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Are two integers equal?

fun (>)( ^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is the first integer greater than the second?

fun (>=)( ^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is the first integer greater or equal to the second?

fun (^)( i : intstd/core/types/int: V, exp : intstd/core/types/int: V ) : intstd/core/types/int: V

Raise an integer i to the power of exp.

fun (~)( i : intstd/core/types/int: V ) : intstd/core/types/int: V

Negate an integer.

fun abs( i : intstd/core/types/int: V ) : intstd/core/types/int: V

Return the absolute value of an integer.

fun bool( i : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Convert an int to a boolean, using Falsestd/core/types/False: bool for 0 and Truestd/core/types/True: bool otherwise.

fun cdiv-exp10( i : intstd/core/types/int: V, n : intstd/core/types/int: V ) : intstd/core/types/int: V
fun cdivmod-exp10( i : intstd/core/types/int: V, n : intstd/core/types/int: V ) : (intstd/core/types/int: V, intstd/core/types/int: V)
fun cmp( ^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V ) : orderstd/core/types/order: V

Compare two integers.

fun count-digits( i : intstd/core/types/int: V ) : intstd/core/types/int: V

Return the number of decimal digits of i. Return 0 when i(==)std/core/int/(==): (x : int, y : int) -> bool0.

fun dec( i : intstd/core/types/int: V ) : intstd/core/types/int: V

Decrement.

fun divmod( x : intstd/core/types/int: V, y : intstd/core/types/int: V ) : (intstd/core/types/int: V, intstd/core/types/int: V)

Euclidean-0 division & modulus. Euclidean division is defined as: For any D and d where d!=0 , we have:

  1. D == d*(D/d) + (D%d)
  2. D%d is always positive where 0 <= D%d < abs(d)

Moreover, Euclidean-0 is a total function, for the case where d(==)std/core/int/(==): (x : int, y : int) -> bool0 we have that D%0 == D and D/0 == 0 . So property (1) still holds, but not property (2).

Useful laws that hold for Euclidean-0 division:

See also Division and modulus for computer scientists, Daan Leijen, 2001 for further information (available at: https://​www.​microsoft.​com/​en-​us/​research/​wp-​content/​uploads/​2016/​02/​divmodnote-​letter.​pdf).

fun divmod-exp10( i : intstd/core/types/int: V, n : intstd/core/types/int: V ) : (intstd/core/types/int: V, intstd/core/types/int: V)
fun exp10( exp : intstd/core/types/int: V ) : intstd/core/types/int: V

Calculate 10^exp.

fun exp2( exp : intstd/core/types/int: V ) : intstd/core/types/int: V

Calculate 2^exp.

fun inc( i : intstd/core/types/int: V ) : intstd/core/types/int: V

Increment.

fun int16( i : intstd/core/types/int: V ) : int16std/core/types/int16: V

Clamp an intstd/core/types/int: V to fit in an int16std/core/types/int16: V.

fun int8( i : intstd/core/types/int: V ) : int8std/core/types/int8: V

Clamp an intstd/core/types/int: V to fit in an int8std/core/types/int8: V.

fun intptr_t( i : intstd/core/types/int: V ) : intptr_tstd/core/types/intptr_t: V

Clamp an intstd/core/types/int: V to fit in an intptr_tstd/core/types/intptr_t: V.

fun is-even( i : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is this an even integer?

fun is-exp10( i : intstd/core/types/int: V ) : intstd/core/types/int: V

Return the number of ending 0 digits of i. Return 0 when i(==)std/core/int/(==): (x : int, y : int) -> bool0.

fun is-neg( i : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is the integer negative (strictly smaller than zero).

fun is-odd( i : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is this an odd integer?

fun is-pos( i : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is the integer positive (strictly greater than zero).

fun is-zero( ^x : intstd/core/types/int: V ) : boolstd/core/types/bool: V

Is this equal to zero?

fun max( i : intstd/core/types/int: V, j : intstd/core/types/int: V ) : intstd/core/types/int: V

Return the maximum of two integers.

fun maybe( i : intstd/core/types/int: V ) : maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>

Transform an integer to a maybe type, using Nothingstd/core/types/Nothing: forall<a> maybe<a> for 0.

fun mbint( m : maybestd/core/types/maybe: V -> V<intstd/core/types/int: V> ) : intstd/core/types/int: V

Convert a maybe<intstd/core/types/int: V> to an intstd/core/types/int: V using zero for Nothingstd/core/types/Nothing: forall<a> maybe<a>.

fun min( i : intstd/core/types/int: V, j : intstd/core/types/int: V ) : intstd/core/types/int: V

Return the minimum of two integers.

fun mul-exp10( i : intstd/core/types/int: V, n : intstd/core/types/int: V ) : intstd/core/types/int: V
fun negate( i : intstd/core/types/int: V ) : intstd/core/types/int: V
fun order( i : intstd/core/types/int: V ) : orderstd/core/types/order: V
fun order2( x : intstd/core/types/int: V, y : intstd/core/types/int: V ) : order2std/core/types/order2: V -> V<intstd/core/types/int: V>

Order two integers in ascending order.

fun parse-int( s : stringstd/core/types/string: V, hex : ? boolstd/core/types/bool: V ) : maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>

Parse an integer. If an illegal digit character is encountered Nothingstd/core/types/Nothing: forall<a> maybe<a> is returned. An empty string, or a string starting with white space will result in Nothingstd/core/types/Nothing: forall<a> maybe<a> A string can start with a (-)std/core/int/(-): (x : int, y : int) -> int sign for negative numbers, and with 0x or 0X for hexadecimal numbers (in which case the hex parameter is ignored).

fun pow( i : intstd/core/types/int: V, exp : intstd/core/types/int: V ) : intstd/core/types/int: V

Raise an integer i to the power of exp.

fun show( i : intstd/core/types/int: V ) : stringstd/core/types/string: V

Convert an intstd/core/types/int: V to a string.

fun sign( ^i : intstd/core/types/int: V ) : orderstd/core/types/order: V

Compare an integer i with zero.

fun ssize_t( i : intstd/core/types/int: V ) : ssize_tstd/core/types/ssize_t: V

Convert an integer to an ssize_tstd/core/types/ssize_t: V. The number is clamped to the maximal or minimum ssize_tstd/core/types/ssize_t: V value if it is outside the range of an ssize_tstd/core/types/ssize_t: V. Needed for evidence indices in std/core/hndstd/core/hnd.

fun uint8( i : intstd/core/types/int: V ) : int8std/core/types/int8: V

Clamp an intstd/core/types/int: V to fit in an int8std/core/types/int8: V but interpret the intstd/core/types/int: V as an unsigned 8-bit value, and clamp between 0 and 255.

private import std/core/typesstd/core/types