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:

  1. number The smaller number.
  2. number The bigger number.

Calculation

factorial(n)
The factorial n! is 1*2*3*...*n.

Parameters:

  • n Integer Negative input means -1*n!.

Returns:

    Integer
floor(n, base)
Floor of n for non-decimal bases.

Parameters:

Returns:

    Integer

Usage:

    print(Math.floor(33, 16))
    >  32
    print(Math.floor(-1, 32)
    > -32
    
ceil(n, base)
Ceil of n for non-decimal bases.

Parameters:

Returns:

    Integer

Conversion of Rotation

Converts between anglular units.
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.

ori2dir()
ori2deg()
deg2ori()
deg2dir()
dir2ori()
dir2deg()
deg2rad()
rad2deg()
generated by LDoc 1.4.6 Last updated 2021-09-10 19:51:19