Skip to content

Int

fn to_string(n: Int) -> String

Decimal digits, with - if negative.

fn parse(s: String) -> Int fails ParseError

Reads decimal digits, with an optional leading - or +: Int.parse("-42") is -42. Fails with ParseError if anything else is in s (including spaces), or if the value is outside the range of Int.

fn checked_add(a: Int, b: Int) -> Option[Int]

None on overflow.

fn bit_and(a: Int, b: Int) -> Int

Reads as flags.bit_and(MASK).

fn bit_or(a: Int, b: Int) -> Int

Bitwise OR.

fn bit_xor(a: Int, b: Int) -> Int

Bitwise exclusive OR.

fn bit_not(n: Int) -> Int

Same as -n - 1.

fn shift_left(n: Int, by: Int) -> Int

0 if by is 32 or more; a defect if by is negative.

fn shift_right(n: Int, by: Int) -> Int

Arithmetic shift: fills the high bits with the sign. 0 or -1 if by is 32 or more; a defect if by is negative.

fn shift_right_unsigned(n: Int, by: Int) -> Int

Logical shift: fills the high bits with 0. 0 if by is 32 or more; a defect if by is negative.

fn max(a: Int, b: Int) -> Int

Returns the larger value, or a when equal.

fn min(a: Int, b: Int) -> Int

Returns the smaller value, or a when equal.

fn abs(n: Int) -> Int

Absolute value. The minimum Int wraps back to itself, like integer negation.