# Math `[Shared]`

Math is a module to extend Lua's standard mathematical library with additional utility functions for common calculations and operations needed in game development. It provides helpful functions for interpolation, rounding with precision, and other mathematical operations that aren't available in the base Lua math library.

## Math Functions

### math.clamp()

Clamps a number between a minimum and maximum value. <br>

#### Syntax

```lua
math.clamp(x, min, max)
```

#### Parameters

`x` : _number_
> The number to clamp
>

`min` : _number_
> The minimum value
>

`max` : _number_
> The maximum value
>

#### Return Value

Type : _number_

> The clamped number

---

### math.fromHex()

Converts a hexadecimal string to an integer. <br>

#### Syntax

```lua
math.fromHex(hex)
```

#### Parameters

`hex` : _string_
> The hexadecimal string to convert, with or without "0x" prefix
>

#### Return Value

Type : _integer_

> The integer representation

---

### math.lerp()

Performs linear interpolation between two values. <br>

#### Syntax

```lua
math.lerp(a, b, t)
```

#### Parameters

`a` : _number_
> The starting value
>

`b` : _number_
> The ending value
>

`t` : _number_
> The interpolation factor, usually between 0 and 1
>

#### Return Value

Type : _number_

> The interpolated value between a and b

---

### math.round()

Rounds a number to the specified decimal precision. <br>

#### Syntax

```lua
math.round(number, precision)
```

#### Parameters

`number` : _number_
> The number to round
>

`precision` : _number_ `[Optional]`
> The number of decimal places to round to <br> default:0
>

#### Return Value

Type : _number_

> The rounded number

---

### math.toHex()

Converts a number to hexadecimal string representation. <br>

#### Syntax

```lua
math.toHex(n, prefix)
```

#### Parameters

`n` : _integer_
> The integer to convert
>

`prefix` : _boolean_ `[Optional]`
> Add "0x" prefix, default: false
>

#### Return Value

Type : _string_

> The hexadecimal string representation

---

### math.toSigned()

#### Syntax

```lua
math.toSigned(n)
```
