std/num/int32▲toc

32-bit signed integers.

Using 32-bit signed two's complement representation with wrapping on overflow, e.g. max-int32std/num/int32/max-int32: int32 + 1.int32 == min-int32std/num/int32/min-int32: int32.

fun bool/int32( b : boolstd/core/types/bool: V ) : int32std/core/types/int32: V

Convert a boolean to an int32std/core/types/int32: V.

fun hilo/int( (int32std/core/types/int32: V, int32std/core/types/int32: V) ) : intstd/core/types/int: V

Convert a pair (histd/num/int32/hi: (i : int32) -> int32,lostd/num/int32/lo: (i : int32) -> int32) to a signed integer, where (histd/num/int32/hi: (i : int32) -> int32,lostd/num/int32/lo: (i : int32) -> int32).int == histd/num/int32/hi: (i : int32) -> int32.int * 0x1_0000_0000 + lostd/num/int32/lo: (i : int32) -> int32.uint.

fun hilo/int32( hi : int32std/core/types/int32: V, lo : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Create an int32std/core/types/int32: V from the give histd/num/int32/hi: (i : int32) -> int32 and lostd/num/int32/lo: (i : int32) -> int32 16-bit numbers. Preserves the sign of histd/num/int32/hi: (i : int32) -> int32.

fun hilo/uint( (int32std/core/types/int32: V, int32std/core/types/int32: V) ) : intstd/core/types/int: V

Convert a pair (histd/num/int32/hi: (i : int32) -> int32,lostd/num/int32/lo: (i : int32) -> int32) to an unsigned integer, where (histd/num/int32/hi: (i : int32) -> int32,lostd/num/int32/lo: (i : int32) -> int32).uint == histd/num/int32/hi: (i : int32) -> int32.uint * 0x1_0000_0000 + lostd/num/int32/lo: (i : int32) -> int32.uint.

fun range/fold-int32( start : int32std/core/types/int32: V, end : int32std/core/types/int32: V, init : a, ^f : (int32std/core/types/int32: V, a) -> e a ) : e a

Fold over the range [start,end] (including end).

fun range/fold-while-int32( start : int32std/core/types/int32: V, end : int32std/core/types/int32: V, init : a, f : (int32std/core/types/int32: V, a) -> e maybestd/core/types/maybe: V -> V<a> ) : e a

Iterate over the range [start,end] (including end).

fun range/for-while32( start : int32std/core/types/int32: V, end : int32std/core/types/int32: V, action : (int32std/core/types/int32: V) -> e maybestd/core/types/maybe: V -> V<a> ) : e maybestd/core/types/maybe: V -> V<a>

Executes action for each integer between start upto end (including both start and end ). If start > end the function returns without any call to action . If action returns Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>, the iteration is stopped and the result returned.

fun range/for32( start : int32std/core/types/int32: V, end : int32std/core/types/int32: V, action : (int32std/core/types/int32: V) -> e () ) : e ()

Executes action for each integer between start upto end (including both start and end ). If start > end the function returns without any call to action .

fun (!=)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Are two 32-bit integers not equal?

fun (%)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Euclidean-0 modulus. See (/):(x : int32std/core/types/int32: V, y : int32std/core/types/int32: V) -> int32std/core/types/int32: V division for more information.

fun (*)( int32std/core/types/int32: V, int32std/core/types/int32: V ) : int32std/core/types/int32: V

Multiply two 32-bit integers.

fun (+)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Add two 32-bit integers.

fun (-)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Subtract two 32-bit integers.

fun (/)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Euclidean-0 division. 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==0 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:

Note that an interesting edge case is min-int32std/num/int32/min-int32: int32 / -1 which equals min-int32std/num/int32/min-int32: int32 since in modulo 32-bit arithmetic min-int32std/num/int32/min-int32: int32 == -1 * min-int32std/num/int32/min-int32: int32 == -1 * (min-int32std/num/int32/min-int32: int32 / -1) + (min-int32std/num/int32/min-int32: int32 % -1) satisfying property (1). Of course (min-int32std/num/int32/min-int32: int32 + 1) / -1 is again positive (namely max-int32std/num/int32/max-int32: int32).

See also Division and modulus for computer scientists, Daan Leijen, 2001 pdf .

fun (<)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Is the first 32-bit integer smaller than the second?

fun (<=)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Is the first 32-bit integer smaller or equal to the second?

fun (==)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Are two 32-bit integers equal?

fun (>)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Is the first 32-bit integer larger than the second?

fun (>=)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Is the first 32-bit integer larger or equal to the second?

fun (^)( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Take the bitwise xor of two int32std/core/types/int32: Vs.

fun (~)( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Negate an 32-bit integer.

fun abs( i : int32std/core/types/int32: V ) : exnstd/core/exn/exn: (E, V) -> V int32std/core/types/int32: V

Return the absolute value of an integer. Raises an exception if the int32std/core/types/int32: V is min-int32std/num/int32/min-int32: int32 (since the negation of min-int32std/num/int32/min-int32: int32 equals itself and is still negative).

fun abs0( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Return the absolute value of an integer. Returns 0 if the int32std/core/types/int32: V is min-int32std/num/int32/min-int32: int32 (since the negation of min-int32std/num/int32/min-int32: int32 equals itself and is still negative).

fun and( int32std/core/types/int32: V, int32std/core/types/int32: V ) : int32std/core/types/int32: V

Take the bitwise and of two int32std/core/types/int32: Vs.

fun bit-gather( i : int32std/core/types/int32: V, m : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Bit gather (also known as pext or parallel bit extract). For each 1-bit in mask m, extract the corresponding bit from i and write it into contiguous lower bits in the result. The remaining bits in the result are zero.

bgather(0x1234.int32, 0x0F0F.int32).show-hex == "0x24"

Here is how to decode a 4-byte utf-8 encoded character i:

bgather(i,0x3F3F3F3F.int32).

fun bit-reverse( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Reverse the bits in an int32std/core/types/int32: V.

fun bit-scatter( i : int32std/core/types/int32: V, m : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Bit scatter (also known as pdep or parallel bit deposit). For each 1-bit in mask m, set the corresponding bit in the result from the contiguous lower bits of i. Any bits not set according to the mask are set to zero.

bscatter(0x1234.int32, 0x0F0F.int32).show-hex == "0x304".

fun bit-unzip( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

De-interleave the bits in i such that the odd bits are gathered in the hi 16-bits of the result, and the even bits (starting at bit 0) end up in the lo 16-bits of the result. bit-unzipstd/num/int32/bit-unzip: (i : int32) -> int32(x).andstd/num/int32/and: (int32, int32) -> int32(0xFFFF) == bit-gatherstd/num/int32/bit-gather: (i : int32, m : int32) -> int32(x,0x5555_5555.int32).

fun bit-zip( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Interleave the hi 16-bits with the lo 16-bits of the argument i such that the hi bits are spread over the odd bits and the lo bits over the even bits of the result (starting at bit 0). bit-zipstd/num/int32/bit-zip: (i : int32) -> int32(x.andstd/num/int32/and: (int32, int32) -> int32(0xFFFF)) == bit-scatterstd/num/int32/bit-scatter: (i : int32, m : int32) -> int32(x,0x5555_5555.int32).

val bits-int32: int32std/core/types/int32: V

The number of bits in an int32std/core/types/int32: V (always 32).

fun bool( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Convert an int32std/core/types/int32: V to a boolean.

fun byte-reverse( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Reverse the bytes in an int32std/core/types/int32: V.

fun cdiv( i : int32std/core/types/int32: V, j : int32std/core/types/int32: V ) : exnstd/core/exn/exn: (E, V) -> V int32std/core/types/int32: V

Truncated division (as in C). See also (/):(x : int32std/core/types/int32: V, y : int32std/core/types/int32: V) -> int32std/core/types/int32: V.

fun clmul( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Carry-less multiplication (or xor multiplication). See also https://​en.​wikipedia.​org/​wiki/​Carry-​less_​product Interesting cases: - clmulstd/num/int32/clmul: (x : int32, y : int32) -> int32(x,x) : bit spread, where a zero bit is put in between each input bit. clmulstd/num/int32/clmul: (x : int32, y : int32) -> int32(x,x) == bit-scatterstd/num/int32/bit-scatter: (i : int32, m : int32) -> int32(x,0x5555_5555.int32) == bit-zipstd/num/int32/bit-zip: (i : int32) -> int32(andstd/num/int32/and: (int32, int32) -> int32(x,0xFFFF)) - clmulstd/num/int32/clmul: (x : int32, y : int32) -> int32(x,-1.int32): prefix xor, where each bit is the parity of the corresponding input bit and all input bits before it (the xor sum). clmulstd/num/int32/clmul: (x : int32, y : int32) -> int32(x,-1.int32).shrstd/num/int32/shr: (i : int32, shift : int) -> int32(31).bool == x.paritystd/num/int32/parity: (i : int32) -> bool.

fun clmul_wide( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : (int32std/core/types/int32: V, int32std/core/types/int32: V)

Wide carry-less multiplication (or xor multiplication) to (histd/num/int32/hi: (i : int32) -> int32,lostd/num/int32/lo: (i : int32) -> int32). where (histd/num/int32/hi: (i : int32) -> int32,lostd/num/int32/lo: (i : int32) -> int32).int == histd/num/int32/hi: (i : int32) -> int32.int * 0x1_0000_0000 + lostd/num/int32/lo: (i : int32) -> int32.uint See also https://​en.​wikipedia.​org/​wiki/​Carry-​less_​product.

fun clmulr( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Reverse carry-less multiplication. Defined as clmulrstd/num/int32/clmulr: (x : int32, y : int32) -> int32(x,y) == clmulstd/num/int32/clmul: (x : int32, y : int32) -> int32(x.bit-reversestd/num/int32/bit-reverse: (i : int32) -> int32,y.bitreverse).bitreverse Also clmulrstd/num/int32/clmulr: (x : int32, y : int32) -> int32(x,x) == zipstd/core/list/zip: forall<a,b> (xs : list<a>, ys : list<b>) -> list<(a, b)>(x.andstd/num/int32/and: (int32, int32) -> int32(0xFFFF0000.int32), and zipstd/core/list/zip: forall<a,b> (xs : list<a>, ys : list<b>) -> list<(a, b)>(x) == clmulstd/num/int32/clmul: (x : int32, y : int32) -> int32(x,x) | clmulrstd/num/int32/clmulr: (x : int32, y : int32) -> int32(x,x).

fun clrsb( i : int32std/core/types/int32: V ) : intstd/core/types/int: V

Count leading redundant sign bits (i.e. the number of bits following the most significant bit that are identical to it).

fun clz( i : int32std/core/types/int32: V ) : intstd/core/types/int: V

Count leading zero bits. Returns 32 if i is zero.

fun cmod( i : int32std/core/types/int32: V, j : int32std/core/types/int32: V ) : exnstd/core/exn/exn: (E, V) -> V int32std/core/types/int32: V

Truncated modulus (as in C). See also (%):(x : int32std/core/types/int32: V, y : int32std/core/types/int32: V) -> int32std/core/types/int32: V.

fun cmp( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : orderstd/core/types/order: V
fun ctz( i : int32std/core/types/int32: V ) : intstd/core/types/int: V

Count trailing zero bits. Returns 32 if i is zero.

fun dec( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Decrement a 32-bit integer.

fun divmod( x : int32std/core/types/int32: V, y : int32std/core/types/int32: V ) : (int32std/core/types/int32: V, int32std/core/types/int32: V)
fun float64( i : int32std/core/types/int32: V ) : float64std/core/types/float64: V

Convert an 32-bit integer to a float64.

fun fold-int32( n : int32std/core/types/int32: V, init : a, ^f : (int32std/core/types/int32: V, a) -> e a ) : e a

Fold over the 32-bit integers 0 to malformed identifier: a dash must be preceded by a letter or digit, and followed by a letter.

fun fold-while-int32( n : int32std/core/types/int32: V, init : a, f : (int32std/core/types/int32: V, a) -> e maybestd/core/types/maybe: V -> V<a> ) : e a

Iterate over the 32-bit integers 0 to malformed identifier: a dash must be preceded by a letter or digit, and followed by a letter.

fun for-while32( n : int32std/core/types/int32: V, action : (int32std/core/types/int32: V) -> e maybestd/core/types/maybe: V -> V<a> ) : e maybestd/core/types/maybe: V -> V<a>
fun for32( n : int32std/core/types/int32: V, action : (int32std/core/types/int32: V) -> e () ) : e ()
fun hi( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Return the top 16-bits of an int32std/core/types/int32: V. Preserves the sign.

fun i32( i : intstd/core/types/int: V ) : int32std/core/types/int32: V

Convenient shorthand to int32, e.g. 1234.i32std/num/int32/i32: (i : int) -> int32.

fun imul( i : int32std/core/types/int32: V, j : int32std/core/types/int32: V ) : (int32std/core/types/int32: V, int32std/core/types/int32: V)

Full 32x32 bit signed multiply to (histd/num/int32/hi: (i : int32) -> int32,lostd/num/int32/lo: (i : int32) -> int32). where imulstd/num/int32/imul: (i : int32, j : int32) -> (int32, int32)(x,y).int == x.int * y.int.

fun inc( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Increment a 32-bit integer.

fun int( i : int32std/core/types/int32: V ) : intstd/core/types/int: V

Convert an int32std/core/types/int32: V to an intstd/core/types/int: V.

fun int32( i : intstd/core/types/int: V ) : int32std/core/types/int32: V

Convert an integer to an int32std/core/types/int32: V. The number is clamped to the maximal or minimum int32std/core/types/int32: V value if it is outside the range of an int32std/core/types/int32: V. Needed for control flow contexts in std/core/hnd.

fun is-even( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Returns true if the integer i is an even number.

fun is-neg( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Is the 32-bit integer negative?

fun is-odd( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Returns true if the integer i is an odd number.

fun is-pos( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Is the 32-bit integer positive (i.e. larger than zero)?

fun is-zero( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Is the 32-bit integer equal to zero?

fun list32( lo : int32std/core/types/int32: V, hi : int32std/core/types/int32: V ) : liststd/core/types/list: V -> V<int32std/core/types/int32: V>

Create a list with 32-bit integer elements from lostd/num/int32/lo: (i : int32) -> int32 to histd/num/int32/hi: (i : int32) -> int32 (including histd/num/int32/hi: (i : int32) -> int32).

fun lo( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Return the low 16-bits of an int32std/core/types/int32: V.

fun max( i : int32std/core/types/int32: V, j : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Return the maximum of two integers.

val max-int32: int32std/core/types/int32: V

The maximal integer value before overflow happens.

fun min( i : int32std/core/types/int32: V, j : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Return the minimum of two integers.

val min-int32: int32std/core/types/int32: V

The minimal integer value before underflow happens.

fun negate( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Negate a 32-bit integer.

fun not( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Bitwise not of an int32std/core/types/int32: V, i.e. flips all bits.

val one: int32std/core/types/int32: V

The 32-bit integer with value 1.

fun or( int32std/core/types/int32: V, int32std/core/types/int32: V ) : int32std/core/types/int32: V

Take the bitwise or of two int32std/core/types/int32: Vs.

fun orc( i : int32std/core/types/int32: V ) : int32std/core/types/int32: V

Or-combine: for every byte b in the argument i, the corresponding byte in the result becomes 0 if b==0, and 0xFF otherwise.

fun parity( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V

Is the popcountstd/num/int32/popcount: (i : int32) -> int even?

fun popcount( i : int32std/core/types/int32: V ) : intstd/core/types/int: V

Count number of 1-bits (also known as population count or hamming weight).

fun rotl( i : int32std/core/types/int32: V, shift : intstd/core/types/int: V ) : int32std/core/types/int32: V

Bitwise rotate an int32std/core/types/int32: V n % 32 bits to the left.

fun rotr( i : int32std/core/types/int32: V, shift : intstd/core/types/int: V ) : int32std/core/types/int32: V

Bitwise rotate an int32std/core/types/int32: V n % 32 bits to the right.

fun sar( i : int32std/core/types/int32: V, shift : intstd/core/types/int: V ) : int32std/core/types/int32: V

Arithmetic shift an int32std/core/types/int32: V to the right by n % 32 bits. Shifts in the sign bit from the left.

fun shl( i : int32std/core/types/int32: V, shift : intstd/core/types/int: V ) : int32std/core/types/int32: V

Shift an int32std/core/types/int32: V i to the left by n & 31 bits.

fun show( i : int32std/core/types/int32: V ) : stringstd/core/types/string: V

Convert an int32std/core/types/int32: V to a string.

fun show-hex( i : int32std/core/types/int32: V, width : ? intstd/core/types/int: V, use-capitals : ? boolstd/core/types/bool: V, pre : ? stringstd/core/types/string: V ) : stringstd/core/types/string: V

Show an int32std/core/types/int32: V in hexadecimal notation The width parameter specifies how wide the hex value is where '0' is used to align.
The use-capitals parameter (= Truestd/core/types/True: bool) determines if captical letters should be used to display the hexadecimal digits.
The pre (="0x") is an optional prefix for the number (goes between the sign and the number).

fun show-hex32( i : int32std/core/types/int32: V, width : ? intstd/core/types/int: V, use-capitals : ? boolstd/core/types/bool: V, pre : ? stringstd/core/types/string: V ) : stringstd/core/types/string: V

Show an int32std/core/types/int32: V in hexadecimal notation interpreted as an unsigned 32-bit value. The width parameter specifies how wide the hex value is where '0' is used to align.
The use-capitals parameter (= Truestd/core/types/True: bool) determines if captical letters should be used to display the hexadecimal digits.
The pre (="0x") is an optional prefix for the number.

fun shr( i : int32std/core/types/int32: V, shift : intstd/core/types/int: V ) : int32std/core/types/int32: V

Logical shift an int32std/core/types/int32: V to the right by n % 32 bits. Shift in zeros from the left.

fun sign( i : int32std/core/types/int32: V ) : orderstd/core/types/order: V

Compare the argument against zero.

fun sum32( ^xs : liststd/core/types/list: V -> V<int32std/core/types/int32: V> ) : int32std/core/types/int32: V
fun uint( i : int32std/core/types/int32: V ) : intstd/core/types/int: V

Convert an int32std/core/types/int32: V to an intstd/core/types/int: V but interpret the int32std/core/types/int32: V as a 32-bit unsigned value.

fun uint32( i : intstd/core/types/int: V ) : int32std/core/types/int32: V

Convert an intstd/core/types/int: V to int32std/core/types/int32: V but interpret the int as an unsigned 32-bit value. i is clamped between 0 and 0xFFFFFFFF.
0x7FFF_FFFF.uint32std/num/int32/uint32: (i : int) -> int32 == 0x7FFF_FFFF.int32 == max-int32std/num/int32/max-int32: int32
0x8000_0000.uint32std/num/int32/uint32: (i : int) -> int32 == -0x8000_0000.int32 == min-int32std/num/int32/min-int32: int32
0xFFFF_FFFF.uint32std/num/int32/uint32: (i : int) -> int32 == -1.int32.

fun umul( i : int32std/core/types/int32: V, j : int32std/core/types/int32: V ) : (int32std/core/types/int32: V, int32std/core/types/int32: V)

Full 32x32 bit unsigned multiply to (histd/num/int32/hi: (i : int32) -> int32,lostd/num/int32/lo: (i : int32) -> int32). where umulstd/num/int32/umul: (i : int32, j : int32) -> (int32, int32)(x,y).uint == x.uint * y.uint.

fun unsafe-cdiv( int32std/core/types/int32: V, int32std/core/types/int32: V ) : int32std/core/types/int32: V

Truncated division (as in C). See also (/):(x : int32std/core/types/int32: V, y : int32std/core/types/int32: V) -> int32std/core/types/int32: V.

fun unsafe-cmod( int32std/core/types/int32: V, int32std/core/types/int32: V ) : int32std/core/types/int32: V

Truncated modulus (as in C). See also (%):(x : int32std/core/types/int32: V, y : int32std/core/types/int32: V) -> int32std/core/types/int32: V.

fun xor( int32std/core/types/int32: V, int32std/core/types/int32: V ) : int32std/core/types/int32: V

Take the bitwise xor of two int32std/core/types/int32: Vs.

val zero: int32std/core/types/int32: V

The zero 32-bit integer.

private import std/core/typesstd/core/types, std/core/hndstd/core/hnd, std/core/exnstd/core/exn, std/core/boolstd/core/bool, std/core/orderstd/core/order, std/core/charstd/core/char, std/core/intstd/core/int, std/core/vectorstd/core/vector, std/core/stringstd/core/string, std/core/sslicestd/core/sslice, std/core/liststd/core/list, std/core/maybestd/core/maybe, std/core/eitherstd/core/either, std/core/tuplestd/core/tuple, std/core/showstd/core/show, std/core/debugstd/core/debug, std/core/delayedstd/core/delayed, std/core/consolestd/core/console, std/corestd/core, std/core/undivstd/core/undiv