Int
1 type21 functions64-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.
Types
Result
Shorthand for [Ok(a) | Err(e)], the variant this module's fallible
functions return.
Functions
add
Addition, behind +. It wraps on overflow, two's-complement.
sub
Subtraction, behind -. It wraps on overflow, two's-complement.
mul
Multiplication, behind *. It wraps on overflow, two's-complement.
div
Truncating division, behind /. Traps on a zero divisor, and on
div(INT_MIN, -1), whose result does not fit; divChecked does neither.
rem
The remainder of truncating division, behind %: it takes the sign of the
dividend. Traps on a zero divisor.
eq
true when the two are equal, behind ==.
ne
true when the two differ. a != b is eq negated, not a call to ne.
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. A value outside the Int range is an
InvalidInt rather than a wrapped one.
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. Integers past 2^53 may not be exact.