# Math

## Abs

`Abs(x) -> number`

Returns the absolute value of a number.
Returns `undefined`

if the input is nullish.

## Angle

`Angle(x) -> number`

Returns the angle of a vector in radians.
Returns `undefined`

if the input is nullish.

## AngleDelta

`AngleDelta(a, b) -> number`

Returns the smallest amount of turn required to get from the angle `a`

to the angle `b`

.
May be positive or negative.
Returns `0`

if one or both of the inputs is nullish.

## Ceiling

`Ceiling(x) -> number`

Returns the smallest integer greater than or equal to a number.
Returns `undefined`

if the input is nullish.

## Clamp

`value.Clamp(min, max) -> number`

Returns a number clamped between `min`

and `max`

.
If `min`

or `max`

are nullish, no clamping will be performed on that side.
Returns `undefined`

if the `value`

is nullish.

## Cos

`Cos(angle) -> number`

Returns the cosine of an angle in radians.
Returns `undefined`

if the input is nullish.

## Direction

`Direction(x) -> vector`

Returns a unit vector in the direction of `x`

.

- If
`x`

is a Number, returns a Vector of angle`x`

and length 1. - If
`x`

is a Vector, returns a Vector with the same angle as`x`

but with length 1. This is sometimes called "normalizing" a vector in maths or other game engines.

Returns `undefined`

if the input is nullish.

## Distance

`Distance(a, b) -> number`

Returns the distance between two points.
`a`

and `b`

must both be Vectors.
Returns `0`

if one or both of the inputs is nullish.

## Dot

`Dot(a, b) -> vector`

Returns the dot product of two Vectors.
Returns `0`

if one or both of the inputs is nullish.

## Floor

`Floor(x) -> number`

Returns the largest integer less than or equal to a number.
Returns `undefined`

if the input is nullish.

## Max

`Max(a, b) -> value`

Returns the larger of two values. If both values are Numbers, the larger Number is returned. If both values are Vectors, the longer Vector is returned. If either value is nullish, the other value is returned.

## Min

`Min(a, b) -> value`

Returns the smaller of two values. If both values are Numbers, the smaller Number is returned. If both values are Vectors, the shorter Vector is returned. If either value is nullish, the other value is returned.

## Mix

`Mix(alpha, from, to) -> value`

Returns a value that is a mix between `from`

and `to`

.
The mixing is done using linear interpolation.
`alpha`

controls the amount of blending and should be a value between `0`

and `1`

,
where `0`

is `from`

and `1`

is `to`

. Defaults to `0`

if not provided.

If only one of the inputs is nullish, the other input is returned.

## Pi

`Pi -> number`

Returns the value of PI.

## Quantize

`Quantize(x, quant) -> number`

Returns the input `x`

rounded to the nearest multiple of `quant`

.
Both `x`

and `quant`

can be a Number or a Vector.

If the input is a Vector, quantizes both components of the Vector.
If `quant`

is also a Vector, quantizes each component of the input using the corresponding component of `quant`

.

Returns `undefined`

if either input is nullish.

**Examples:**

`let output1 = Quantize(9.7, 2) // output1 is 10`

let output2 = Quantize(@(9.7, 10.2), 2) // output2 is @(10, 10)

let output3 = Quantize(@(9.7, 10.2), @(2, 3)) // output3 is @(10, 9)

## Random

`this?.Random -> number`

Returns a random floating-point number between `0`

(inclusive) and `1`

(exclusive).

`this`

(Entity): Determine's which entity's random number generator to use. If nullish, uses`World`

. This is optional and is only used to help increase stability if a network rollback occurs.

## RandomVector

`this?.RandomVector -> vector`

Returns a Vector with a random angle and length 1.

`this`

(Entity): Determine's which entity's random number generator to use. If nullish, uses`World`

. This is optional and is only used to help increase stability if a network rollback occurs.

## Rotate

`x.Rotate(rotate) -> vector`

Returns a vector rotated by `rotate`

radians.
If `rotate`

is nullish, the input is returned unchanged.
Returns `undefined`

if the input is nullish.

## RotateLeft

`RotateLeft(x) -> vector`

Returns a vector rotated 90 degrees to the left.
Returns `undefined`

if the input is nullish.

## RotateRight

`RotateRight(x) -> vector`

Returns a vector rotated 90 degrees to the right.
Returns `undefined`

if the input is nullish.

## Round

`Round(x) -> number`

Returns the integer nearest to the number.
If the value is halfway between two integers, rounds away from zero.
Returns `undefined`

if the input is nullish.

## Sign

`Sign(x) -> number`

Returns the sign of a number.

- If the number is positive, returns
`1`

. - If the number is negative, returns
`-1`

. - If the number is
`0`

, returns`0`

.

Returns `undefined`

if the input is nullish.

## SignedRandom

`this?.SignedRandom -> number`

Returns a random floating-point number between `-1`

(inclusive) and `1`

(inclusive).

`this`

(Entity): Determine's which entity's random number generator to use. If nullish, uses`World`

. This is optional and is only used to help increase stability if a network rollback occurs.

## Sin

`Sin(angle) -> number`

Returns the sine of an angle in radians.
Returns `undefined`

if the input is nullish.

## Sqrt

`Sqrt(x) -> number`

Returns the square root of a number.
Returns `undefined`

if the input is nullish.

## Tan

`Tan(angle) -> number`

Returns the tangent of an angle in radians.
Returns `undefined`

if the input is nullish.

## Towards

`a.Towards(b, limit) -> vector`

Returns a Vector or Number that moves from `a`

towards `b`

by a maximum step of `limit`

.
In other words, if the distance between `a`

and `b`

is less than `limit`

, returns `b`

,
otherwise returns a point or value `limit`

distance away from `a`

in the direction towards `b`

.
If both `a`

and `b`

are Numbers, performs the calculation in 1-dimension, returning a Number.
If both `a`

and `b`

are Vectors, performs the calculation in 2-dimensions, returning a Vector.

If `a`

is nullish, returns `undefined`

.
If `b`

or `limit`

is nullish, returns `a`

.

## Truncate

`x.Truncate(limit) -> numberOrVector`

Truncates a Vector or Number to a maximum length.
If `x`

is a Vector, returns a Vector with a length of at most `limit`

, but in the same direction.
If `x`

is a Number, returns a Number with an absolute value of at most `limit`

, but with the same sign.
If `limit`

is nullish, returns `x`

unchanged.
If `x`

is nullish, returns `undefined`

.

## TwoPi

`TwoPi -> number`

Returns the value of 2*PI.

## WithX

`vector.WithX(x) -> vector`

Takes a Vector and returns a new Vector with the `x`

component replaced with a new value.
Returns `vector`

unchanged if `x`

is nullish.
Returns `undefined`

if the `vector`

is nullish.

## WithY

`vector.WithY(y) -> vector`

Takes a Vector and returns a new Vector with the `y`

component replaced with a new value.
Returns `vector`

unchanged if `y`

is nullish.
Returns `undefined`

if the `vector`

is nullish.

## X

`vector.X -> number`

Returns the `x`

component of a vector.
Returns `undefined`

if the input is nullish.

## Y

`vector.Y -> number`

Returns the `y`

component of a vector.
Returns `undefined`

if the input is nullish.