---
title: Std.Int
---

Integer conversion, arithmetic, and bitwise operations.

## Functions

### to_float

```saga
fun to_float : Int -> Float
```

Converts an integer to a float.

### parse

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

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

### add

```saga
fun add : Int -> Int -> Int
```

Adds two integers.

### sub

```saga
fun sub : Int -> Int -> Int
```

Subtracts the second integer from the first.

### mul

```saga
fun mul : Int -> Int -> Int
```

Multiplies two integers.

### div

```saga
fun div : Int -> Int -> Int
```

Integer division, truncating towards zero.

### mod

```saga
fun mod : Int -> Int -> Int
```

Returns the remainder of integer division.

### abs

```saga
fun abs : Int -> Int
```

Returns the absolute value.

### min

```saga
fun min : Int -> Int -> Int
```

Returns the smaller of two integers.

### max

```saga
fun max : Int -> Int -> Int
```

Returns the larger of two integers.

### clamp

```saga
fun clamp : Int -> Int -> Int -> Int
```

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

### sign

```saga
fun sign : Int -> Int
```

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

### band

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

Bitwise AND.

### bor

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

Bitwise OR.

### bxor

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

Bitwise XOR.

### bnot

```saga
fun bnot : (n: Int) -> Int
```

Bitwise NOT (ones' complement).

### shift_left

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

Bitwise shift left.

### shift_right

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

Bitwise shift right.

### to_hex

```saga
fun to_hex : Int -> String
```

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

### parse_hex

```saga
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.

