> ## Documentation Index
> Fetch the complete documentation index at: https://lua.starline.one/llms.txt
> Use this file to discover all available pages before exploring further.

# Math

> Use Starline interpolation, angle, vector, and numeric helpers.

Extras on top of Lua's standard `math` library. Everything in [Lua 5.1's math](https://www.lua.org/manual/5.1/manual.html#5.6) is available too (`math.abs`, `math.min`, `math.sin`, ...).

## Lerp

```lua theme={"dark"}
local v = math.Lerp(0, 100, 0.25)   -- 25
```

## Clamp

```lua theme={"dark"}
math.Clamp(v, 0, 1)
```

## Round

```lua theme={"dark"}
math.Round(3.5)   -- 4
math.Round(-2.5)  -- -3
```

Half-away-from-zero.

## Sign

```lua theme={"dark"}
math.Sign(-4)   -- -1
math.Sign(0)    -- 0
math.Sign(2)    -- 1
```

## Remap

```lua theme={"dark"}
local out = math.Remap(v, 0, 100, 0, 1)
```

Errors on a zero input range.

## NormalizeAngle

```lua theme={"dark"}
math.NormalizeAngle(540)   -- -180
math.NormalizeAngle(-190)  -- 170
```

Wraps degrees to `[-180, 180)`.

## CalcAngle

```lua theme={"dark"}
local angle = math.CalcAngle(from_vec, to_vec)
-- angle.pitch, angle.yaw
```

Returns a `QAngle` pointing from one position to another.

## GetFOV

```lua theme={"dark"}
local fov = math.GetFOV(view_angles, eye_pos, target_pos)
```

Returns the physical angular distance (degrees) between your crosshair and a target point, always in the range `0` through `180`. `view_angles` is a `QAngle`, the other two are `Vector`.

## AngleVectors

```lua theme={"dark"}
local forward, right, up = math.AngleVectors(angle)
```

Decomposes a `QAngle` into three direction `Vector`s. Returns all three.

## VectorAngles

```lua theme={"dark"}
local angle = math.VectorAngles(direction)
```

Converts a direction `Vector` to a `QAngle`.
