Skip to content

math⚓︎

This library is an interface to the standard C math library. This library has been further extended by MWSE. The functions implemented by MWSE are listed here. It provides all its functions inside the table math.

Properties⚓︎

math.epsilon⚓︎

The machine epsilon available for double-precision numbers. This is the difference between 1.0 and the next representable value using lua numbers.

Returns:

  • result (number)

math.fepsilon⚓︎

The machine epsilon available for single-precision numbers. This is the difference between 1.0 and the next representable value for many Morrowind structures.

Returns:

  • result (number)

math.fhuge⚓︎

The machine maximum available value for single-precision numbers. This is the maximum representable value for any floating-point Morrowind structures.

Returns:

  • result (number)

math.nfhuge⚓︎

The machine minimum available value for single-precision numbers. This is the minimum representable value for any floating-point Morrowind structures.

Returns:

  • result (number)

Functions⚓︎

math.clamp⚓︎

Returns a value, limited by upper and lower bounds.

local result = math.clamp(value, min, max)

Parameters:

  • value (number)
  • min (number)
  • max (number)

Returns:

  • result (number)

math.ease.backIn⚓︎

See backIn.

local result = math.ease.backIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.backInOut⚓︎

See backInOut.

local result = math.ease.backInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.backOut⚓︎

See backOut.

local result = math.ease.backOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.bounceIn⚓︎

See bounceIn.

local result = math.ease.bounceIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.bounceInOut⚓︎

See bounceInOut.

local result = math.ease.bounceInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.bounceOut⚓︎

See bounceOut.

local result = math.ease.bounceOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.circIn⚓︎

See circIn.

local result = math.ease.circIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.circInOut⚓︎

See circInOut.

local result = math.ease.circInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.circOut⚓︎

See circOut.

local result = math.ease.circOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.cubicIn⚓︎

See cubicIn.

local result = math.ease.cubicIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.cubicInOut⚓︎

See cubicInOut.

local result = math.ease.cubicInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.cubicOut⚓︎

See cubicOut.

local result = math.ease.cubicOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.elasticIn⚓︎

See elasticIn.

local result = math.ease.elasticIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.elasticInOut⚓︎

See elasticInOut.

local result = math.ease.elasticInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.elasticOut⚓︎

See elasticOut.

local result = math.ease.elasticOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.expoIn⚓︎

See expoIn.

local result = math.ease.expoIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.expoInOut⚓︎

See expoInOut.

local result = math.ease.expoInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.expoOut⚓︎

See expoOut.

local result = math.ease.expoOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.linear⚓︎

Linear interpolation that assumes input and output range of [0, 1].

local result = math.ease.linear(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quadIn⚓︎

See quadIn.

local result = math.ease.quadIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quadInOut⚓︎

See quadInOut.

local result = math.ease.quadInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quadOut⚓︎

See quadOut.

local result = math.ease.quadOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quartIn⚓︎

See quartIn.

local result = math.ease.quartIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quartInOut⚓︎

See quartInOut.

local result = math.ease.quartInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quartOut⚓︎

See quartOut.

local result = math.ease.quartOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quintIn⚓︎

See quintIn.

local result = math.ease.quintIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quintInOut⚓︎

See quintInOut.

local result = math.ease.quintInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.quintOut⚓︎

See quintOut.

local result = math.ease.quintOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.sineIn⚓︎

See sineIn.

local result = math.ease.sineIn(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.sineInOut⚓︎

See sineInOut.

local result = math.ease.sineInOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.sineOut⚓︎

See sineOut.

local result = math.ease.sineOut(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.smoothstep⚓︎

See smoothstep.

local result = math.ease.smoothstep(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.smoothstepInverse⚓︎

See smoothstepInverse.

local result = math.ease.smoothstepInverse(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.springOutMed⚓︎

A custom easing function with some overshoot. See the graph of the function here.

local result = math.ease.springOutMed(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.springOutStrong⚓︎

A custom easing function with some overshoot. See the graph of the function here.

local result = math.ease.springOutStrong(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.springOutTooMuch⚓︎

A custom easing function with some overshoot. See the graph of the function here.

local result = math.ease.springOutTooMuch(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.ease.springOutWeak⚓︎

A custom easing function with some overshoot. See the graph of the function here.

local result = math.ease.springOutWeak(x)

Parameters:

  • x (number)

Returns:

  • result (number)

math.isclose⚓︎

This function compares a and b and returns true if they are close together. This can be useful when comparing floating-point numbers with some degree of tolerance.

local result = math.isclose(a, b, absoluteTolerance, relativeTolerance)

Parameters:

  • a (number): First value.
  • b (number): Second value.
  • absoluteTolerance (number): Default: math.epsilon. The absolute difference allowed between the two numbers. A value of 0.01 will only allow the values to differ by 0.01.
  • relativeTolerance (number): Default: 1e-09. The relative difference allowed between the two numbers. A value of 0.01 will only allow the values to differ by 1%.

Returns:

  • result (number)

math.lerp⚓︎

Performs linear interpolation between values v0 and v1. Returns a value that is t percent between them.

local result = math.lerp(v0, v1, t)

Parameters:

  • v0 (number): First value.
  • v1 (number): Second value.
  • t (number): The decimal percentage used to calculate a point between v0 and v1.

Returns:

  • result (number)

math.nextPowerOfTwo⚓︎

Returns the next power of 2 that is equal to, or greater than, value.

local result = math.nextPowerOfTwo(value)

Parameters:

  • value (number)

Returns:

  • result (integer)

math.remap⚓︎

Returns a value, scaled from expected values [lowIn, highIn] to [lowOut, highOut].

For example, a value of 7 remapped from [0,10] to [0,100] would be 70.

local result = math.remap(value, lowIn, highIn, lowOut, highOut)

Parameters:

  • value (number)
  • lowIn (number)
  • highIn (number)
  • lowOut (number)
  • highOut (number)

Returns:

  • result (number)

math.round⚓︎

Rounds a number to a given count of digits.

local result = math.round(value, digits)

Parameters:

  • value (number)
  • digits (number): Default: 0.

Returns:

  • result (number)