Module optmath

Simple math helper functions

Functions

Math.roundPercent (percent) Rounds a percentage.
Math.roundAwayFromZero (num) Rounds away from zero.
Math.round (num) Rounds a number.
Math.oddEven (number) Determines if a number is odd or even.
Math.tmin (tab, func) Returns the minimum element of a table.
Math.tmax (tab, func) Returns the maximum element of a table.
Math.clamp (value, min, max) Restricts a value within an interval.


Functions

Math.roundPercent (percent)
Rounds a percentage.

Parameters:

  • percent float

Returns:

    int rounded percentage
Math.roundAwayFromZero (num)
Rounds away from zero.

Parameters:

  • num float

Returns:

    int ceiled above 0, floored under 0
Math.round (num)
Rounds a number. No support for decimal points.

Parameters:

  • num float

Returns:

    int rounded number
Math.oddEven (number)
Determines if a number is odd or even.

Parameters:

  • number integer

Returns:

    string "odd" or "even"
Math.tmin (tab, func)
Returns the minimum element of a table. The optional argument func specifies a one-argument ordering function.

Parameters:

Returns:

    dynamic minimum element of a table
Math.tmax (tab, func)
Returns the maximum element of a table. The optional argument func specifies a one-argument ordering function.

Parameters:

Returns:

    dynamic maximum element of a table
Math.clamp (value, min, max)
Restricts a value within an interval.

Parameters:

  • value number
  • min number
  • max number

Returns:

    number value clamped to the interval [min,max]
generated by LDoc 1.5.0 Last updated 2024-03-18 16:45:36