Utils.math module

Extends Lua 5.2 math.

See also

Usage

local math = require('__stdlib__/stdlib/utils/math')

Functions

Math.round(x) Round a number.
Math.sum(...) Calculates the sum of a sequence of values.
Math.arithmetic_mean(x) Calculates the arithmetic mean of a set of values.
Math.geometric_mean(x) Calculates the geometric mean of a set of values.
Math.harmonic_mean(...) Calculates the harmonic mean of a set of values.
Math.quadratic_mean(...) Calculates the quadratic mean of a set of values.
Math.generalized_mean(p, ...) Calculates the generalized mean (to a specified power) of a set of values.
Math.weighted_mean(x, w) Calculates the weighted mean of a set of values.
Math.midrange_mean(x) Calculates the midrange mean of a set of values.
Math.energetic_mean(x) Calculates the energetic mean of a set of values.
Math.clamp(x[, min=0][, max=1]) Returns the number x clamped between the numbers min and max.
Math.lerp(a, b, amount) Linear interpolation or 2 numbers.
Math.smooth(a, b, amount) Smooth.
Math.approximately(a, b) Approximately the same
Math.is_number(x) Is x a number.
Math.is_integer(x) Is x an integer.
Math.is_unsigned(x) Is x unsigned.

Functions

# Math.round(x)

Round a number.

Parameters: Returns:
# Math.sum(...)

Calculates the sum of a sequence of values.

Parameters:
  • ... : (tuple) a tuple of numbers
Returns:
  • (the) sum
# Math.arithmetic_mean(x)

Calculates the arithmetic mean of a set of values.

Parameters:
  • x : (array) an array of numbers
Returns:
  • (number) the arithmetic mean
# Math.geometric_mean(x)

Calculates the geometric mean of a set of values.

Parameters:
  • x : (array) an array of numbers
Returns:
# Math.harmonic_mean(...)

Calculates the harmonic mean of a set of values.

Parameters:
  • ... : (tuple) an array of numbers
Returns:
# Math.quadratic_mean(...)

Calculates the quadratic mean of a set of values.

Parameters:
  • ... : (tuple) an array of numbers
Returns:
# Math.generalized_mean(p, ...)

Calculates the generalized mean (to a specified power) of a set of values.

Parameters:
  • p : (number) power
  • ... : (tuple) an array of numbers
Returns:
  • (number) the generalized mean
# Math.weighted_mean(x, w)

Calculates the weighted mean of a set of values.

Parameters:
  • x : (array) an array of numbers
  • w : (array) an array of number weights for each value
Returns:
# Math.midrange_mean(x)

Calculates the midrange mean of a set of values.

Parameters:
  • x : (array) an array of numbers
Returns:
# Math.energetic_mean(x)

Calculates the energetic mean of a set of values.

Parameters:
  • x : (array) an array of numbers
Returns:
# Math.clamp(x[, min=0][, max=1])

Returns the number x clamped between the numbers min and max.

Parameters: Returns:
  • (number) clamped between min and max
# Math.lerp(a, b, amount)

Linear interpolation or 2 numbers.

Parameters: Returns:
# Math.smooth(a, b, amount)

Smooth.

Parameters: Returns:
# Math.approximately(a, b)

Approximately the same

Parameters: Returns:
# Math.is_number(x)

Is x a number.

Parameters: Returns:
# Math.is_integer(x)

Is x an integer.

Parameters: Returns:
# Math.is_unsigned(x)

Is x unsigned.

Parameters: Returns: