Skip to content
Menu
Contents

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.

Int

1 type21 functions

64-bit signed integers. The arithmetic and comparison operators on Int values call the functions here, so a + b is Int.add(a, b). Arithmetic wraps on overflow, and the division functions without Checked in their name trap on a zero divisor.

Int.divChecked(7, 0)
Returns
Err(DivByZero)

At a glance

  • Result

    Shorthand for [Ok(a) | Err(e)], the variant this module's fallible functions return.

  • add

    Addition, behind +.

  • sub

    Subtraction, behind -.

  • mul

    Multiplication, behind *.

  • div

    Truncating division, behind /.

  • rem

    The remainder of truncating division, behind %: it takes the sign of the dividend.

  • eq

    true when the two are equal, behind ==.

  • ne

    true when the two differ.

  • lt

    true when the first is less than the second, behind <.

  • le

    true when the first is at most the second, behind <=.

  • gt

    true when the first is greater than the second, behind >.

  • ge

    true when the first is at least the second, behind >=.

  • toString

    Decimal digits, with a leading - for a negative number.

  • fromString

    A decimal integer with an optional leading -, and nothing else: no +, no whitespace, no digit separators.

  • abs

    abs(INT_MIN) wraps to INT_MIN.

  • neg

    neg(INT_MIN) wraps to INT_MIN.

  • min

    The smaller of the two.

  • max

    The larger of the two.

  • divChecked

    div without the traps: a zero divisor is DivByZero, and divChecked(INT_MIN, -1) is Ok(INT_MIN), the wrapped result.

  • remChecked

    rem without the trap.

  • modChecked

    The floored modulo: the result takes the sign of the divisor, so modChecked(-1, 3) is Ok(2).

  • toFloat

    The nearest Float.

Types

Result

Result(a, e) = [Ok(a) | Err(e)]

Shorthand for [Ok(a) | Err(e)], the variant this module's fallible functions return.

Functions

add

(Int, Int) -> Intpure

Addition, behind +. It wraps on overflow, two's-complement.

sub

(Int, Int) -> Intpure

Subtraction, behind -. It wraps on overflow, two's-complement.

mul

(Int, Int) -> Intpure

Multiplication, behind *. It wraps on overflow, two's-complement.

div

(Int, Int) -> Intpure

Truncating division, behind /. Traps on a zero divisor, and on div(INT_MIN, -1), whose result does not fit; divChecked does neither.

rem

(Int, Int) -> Intpure

The remainder of truncating division, behind %: it takes the sign of the dividend. Traps on a zero divisor.

eq

(Int, Int) -> Boolpure

true when the two are equal, behind ==.

ne

(Int, Int) -> Boolpure

true when the two differ. a != b is eq negated, not a call to ne.

lt

(Int, Int) -> Boolpure

true when the first is less than the second, behind <.

le

(Int, Int) -> Boolpure

true when the first is at most the second, behind <=.

gt

(Int, Int) -> Boolpure

true when the first is greater than the second, behind >.

ge

(Int, Int) -> Boolpure

true when the first is at least the second, behind >=.

toString

(Int) -> Stringpure

Decimal digits, with a leading - for a negative number.

fromString

(String) -> Result(Int, [InvalidInt | e])pure

A decimal integer with an optional leading -, and nothing else: no +, no whitespace, no digit separators. A value outside the Int range is an InvalidInt rather than a wrapped one.

abs

(Int) -> Intpure

abs(INT_MIN) wraps to INT_MIN.

neg

(Int) -> Intpure

neg(INT_MIN) wraps to INT_MIN.

min

(Int, Int) -> Intpure

The smaller of the two.

max

(Int, Int) -> Intpure

The larger of the two.

divChecked

(Int, Int) -> Result(Int, [DivByZero | e])pure

div without the traps: a zero divisor is DivByZero, and divChecked(INT_MIN, -1) is Ok(INT_MIN), the wrapped result.

remChecked

(Int, Int) -> Result(Int, [DivByZero | e])pure

rem without the trap.

modChecked

(Int, Int) -> Result(Int, [DivByZero | e])pure

The floored modulo: the result takes the sign of the divisor, so modChecked(-1, 3) is Ok(2).

toFloat

(Int) -> Floatpure

The nearest Float. Integers past 2^53 may not be exact.

Reading the tags

pure

Same arguments, same result; touches nothing outside.

pure if arg2 is

Pure when that argument is a pure function; otherwise as impure as it is.

impure

Reads or changes something outside the program.