Ints
Gleam's Int
type represents whole numbers.
There are arithmetic and comparison operators for ints, as well as the equality operator which works on all types.
When running on the Erlang virtual machine ints have no maximum and minimum size. When running on JavaScript runtimes ints are represented using JavaScript's 64 bit floating point numbers.
The
gleam/int
standard library module contains functions for working with ints.
import gleam/int
pub fn main() {
// Int arithmetic
echo 1 + 1
echo 5 - 1
echo 5 / 2
echo 3 * 3
echo 5 % 2
// Int comparisons
echo 2 > 1
echo 2 < 1
echo 2 >= 1
echo 2 <= 1
// Equality works for any type
echo 1 == 1
echo 2 == 1
// Standard library int functions
echo int.max(42, 77)
echo int.clamp(5, 10, 20)
}