SagaSaga
Standard Library

Std.Int

Integer conversion, arithmetic, and bitwise operations.

Functions

to_float

fun to_float : Int -> Float

Converts an integer to a float.

parse

fun parse : (s: String) -> Maybe Int

Parses a string as an integer. Returns Nothing if the string is not a valid integer.

add

fun add : Int -> Int -> Int

Adds two integers.

sub

fun sub : Int -> Int -> Int

Subtracts the second integer from the first.

mul

fun mul : Int -> Int -> Int

Multiplies two integers.

div

fun div : Int -> Int -> Int

Integer division, truncating towards zero.

mod

fun mod : Int -> Int -> Int

Returns the remainder of integer division.

abs

fun abs : Int -> Int

Returns the absolute value.

min

fun min : Int -> Int -> Int

Returns the smaller of two integers.

max

fun max : Int -> Int -> Int

Returns the larger of two integers.

clamp

fun clamp : Int -> Int -> Int -> Int

Clamps a value to the range [low, high].

sign

fun sign : Int -> Int

Returns -1 for negative, 0 for zero, 1 for positive.

band

fun band : (a: Int) -> (b: Int) -> Int

Bitwise AND.

bor

fun bor : (a: Int) -> (b: Int) -> Int

Bitwise OR.

bxor

fun bxor : (a: Int) -> (b: Int) -> Int

Bitwise XOR.

bnot

fun bnot : (n: Int) -> Int

Bitwise NOT (ones' complement).

shift_left

fun shift_left : (bits: Int) -> (n: Int) -> Int

Bitwise shift left.

shift_right

fun shift_right : (bits: Int) -> (n: Int) -> Int

Bitwise shift right.

to_hex

fun to_hex : Int -> String

Converts an integer into its equivalent lowercase hex string. Negative numbers are prefixed with "-".

parse_hex

fun parse_hex : String -> Maybe Int

Parses a hex string (with optional "-" prefix) as an integer. Accepts both upper and lower case digits. Returns Nothing if invalid.