Module Math
Description
Module Status: Work in progress.
Usage:
local Math = require('__eradicators-library__/erlib/lua/Math')()
Misc
limit(limitA, number, limitB) | Limits an input to a given range. |
swap_if_gtr(a, b) | Conditionally swaps two variables. |
Calculation
factorial(n) | The factorial n! is 1*2*3*...*n. |
floor(n, base) | Floor of n for non-decimal bases. |
ceil(n, base) | Ceil of n for non-decimal bases. |
Conversion of Rotation
ori2dir() | |
ori2deg() | |
deg2ori() | |
deg2dir() | |
dir2ori() | |
dir2deg() | |
deg2rad() | |
rad2deg() |
Misc
- limit(limitA, number, limitB)
-
Limits an input to a given range.
A < n < B, or A > n > B.
Parameters:
Returns:
-
number
The given number or one of the limits.
- swap_if_gtr(a, b)
-
Conditionally swaps two variables.
Parameters:
Returns:
Calculation
- factorial(n)
-
The factorial n! is 1*2*3*...*n.
Parameters:
- n Integer Negative input means -1*n!.
Returns:
- floor(n, base)
-
Floor of n for non-decimal bases.
Parameters:
- n Integer
- base NaturalNumber
Returns:
Usage:
print(Math.floor(33, 16)) > 32 print(Math.floor(-1, 32) > -32
- ceil(n, base)
-
Ceil of n for non-decimal bases.
Parameters:
- n Integer
- base NaturalNumber
Returns:
Conversion of Rotation
Converts between anglular units.
All methods take a single number argument.
All formats use 0 has up/north.
All methods take a single number argument.
All formats use 0 has up/north.
ori: FactorioOrientation. A UnitInterval.
dir: FactorioDirection. A defines direction, an Integer between 0 and 7.
deg: Degrees.
rad: Radians.
Note: Conversion to FactorioDirection will be rounded to nearest direction.