![]() |
Migrate your account | Wiki Discord |
---|
Module:Math/doc
This is the documentation page for Module:Math
Math is an extension of the math STL, containing additional functionality and support. All Math, non-STL, functions are capable of evaluating mathemetical expression strings and provide friendlier error messages than the default error()
function. While more powerful than their STL counterparts, Math's functions comes at the cost of performance. If complex math is done within long looping applications or Lua expense needs to be kept low, consider using the STL functions instead.
Math can be invoked directly ({{#invoke:Math|function|...}}
), invoked from a template ({{template|function|...}}
), or used within other modules.
All math STL objects can be accessed by adding two underscores before the name, e.g.
math.__abs(-7)
- Original math STL abs function
math.abs(-7)
- Math's abs function with error checking and string evaluation
All bit32 STL objects can be accessed by adding two underscores before the name (without the 'b'), e.g.
math.__xor(1, 0)
- Original bit32 STL bxor function
On this Wiki, Math is used in:
- Module:Acquisition
- Module:MasteryRank
- Module:Shared
- Module:Warframes
- Module:Warframes/infobox
- Module:Weapons
- Module:Weapons/infobox
- Template:Math
Usage
Direct Invocation
{{#invoke:Math|function|input1|input2|...}}
Template
In template: {{#invoke:Math|__main}}
In articles: {{template|function|input1|input2|...}}
Module
local p = {}
local math = require('Module:Math')
local pi = math.pi
local absSTL = math.__abs
local function func(input)
-- ...
-- input -> stuff
-- ...
return math.eval(stuff)
end
Documentation
Package items
math.eval(num)
(function)- Evaluates input
- Parameter:
num
The input expression (string) - Returns: eval(num) (number)
math.formatnum(num, code, noCommafy)
(function)- Evaluates and formats input
- Parameters:
num
The input expression (number, string)code
A language code | default 'en' (string; optional)noCommafy
Use comma separators | default false (boolean; optional)
- Returns:
- formatnum(num) (string)
- formatnum(num, 'ar') (string)
- formatnum(num, "", true) (string)
- etc. (string)
math.abs(num)
(function)- Evaluates input and returns the magnitude
- Parameter:
num
The input value (number, string) - Returns: abs(num) (number)
math.acos(num)
(function)- Evaluates input and returns the acos
- Parameter:
num
The input value (number, string) - Returns: acos(num) (number)
math.add(n, m)
(function)- Evaluates inputs and returns the sum
- Parameters:
n
An input value (table, boolean, number, string)m
A second input value (table, boolean, number, string)
- Returns: add(n, m) (table, boolean, number, string)
math.asin(num)
(function)- Evaluates input and returns the asin
- Parameter:
num
The input value (number, string) - Returns: asin(num) (number)
math.atan(num, den)
(function)- Evaluates inputs and returns the atan
- Parameters:
num
The input value (number, string)den
A second input value | default 1 (number, string; optional)
- Returns:
- atan(num) (number)
- atan(num / den) (number)
math.binomial(p, n, r)
(function)- Returns the binomial probability of three inputs
- Parameters:
p
The probability of success (string, number)n
Total number of trials (string, number)r
Number of successes (string, number)
- Returns: Binomial of p, n, and r (number)
math.ceil(num)
(function)- Evaluates input and returns the ceil
- Parameter:
num
The input value (number, string) - Returns: ceil(num) (number)
math.cos(num)
(function)- Evaluates input and returns the cos
- Parameter:
num
The input value (number, string) - Returns: cos(num) (number)
math.cosh(num)
(function)- Evaluates input and returns the cosh
- Parameter:
num
The input value (number, string) - Returns: cosh(num) (number)
math.deg(num)
(function)- Evaluates input and converts into degrees
- Parameter:
num
The input value (number, string) - Returns: deg(num) (number)
math.div(n, m)
(function)- Evaluates inputs and returns the quotient
- Parameters:
n
An input value (table, boolean, number, string)m
A second input value (table, boolean, number, string)
- Returns: div(n, m) (table, boolean, number, string)
math.ex(frame)
(function)- Evaluates inputs and returns the expected value
- Parameter:
frame
inputs (table) - Returns: Expectation range of inputs (string)
math.exp(num)
(function)- Evaluates input and returns the exp
- Parameter:
num
The input value (number, string) - Returns: exp(num) (number)
math.floor(num)
(function)- Evaluates input and returns the floor
- Parameter:
num
The input value (number, string) - Returns: floor(num) (number)
math.frac(num, factor, epsilon)
(function)- Evaluates inputs and returns closest fraction
- Parameters:
num
The input value (number, string)factor
The value to factor out | default '1' (string; optional)epsilon
Number of decimal places to be accurate to | default -5 (10^-5) (number, string; optional)
- Returns: Closest fraction in LaTeX (string)
math.gamma(num)
(function)- Evaluates input and returns the factorial
- Parameter:
num
The input value (number, string) - Returns:
- (num - 1)! (number)
- (num - 1)! scientific notation if larger than 107 (string)
math.gcd(num1, num2)
(function)- Evaluates inputs and return greatest common divider
- Parameters:
num1
The first input value (number, string)num2
The second input value (number, string)
- Returns: GCD(num1, num2) (number)
math.ln(num)
(function)- Evaluates input and returns the natural log
- Parameter:
num
The input value (number, string) - Returns: ln(num) (number)
math.log(num, base)
(function)- Evaluates inputs and returns the log (base x)
- Parameters:
num
The input value (number, string)base
The logarithm base | default 10 (number, string; optional)
- Returns:
- log(num) (number)
- log(num, base) (number)
math.max(nums)
(function)- Evaluates inputs and returns the maximum value
- Parameter:
nums
The input values (table) - Returns:
- max(num1, num2, num3, ...) (number)
- max(nums) (number)
math.min(nums)
(function)- Evaluates inputs and returns the minimum value
- Parameter:
nums
The input values (table) - Returns:
- min(num1, num2, num3, ...) (number)
- min(nums) (number)
math.mod(num, den)
(function)- Evaluates inputs and returns the modulo
- Parameters:
num
The dividend (number, string)den
The divider (number, string)
- Returns: num % den (number)
math.modf(num)
(function)- Evaluates input and returns the integral, fractional, or both parts
- Parameters:
num
The input value (number, string)frame.int
Returns the integer | default false (boolean; optional)frame.dec
Returns the decimal | default true (boolean; optional)
- Returns:
- modf(num) (number)
- modf(num, int=true) (number)
- modf(num, int=true, dec=true) (returns both) (number)
math.mul(n, m)
(function)- Evaluates inputs and returns the product
- Parameters:
n
An input value (table, boolean, number, string)m
A second input value (table, boolean, number, string)
- Returns: mul(n, m) (table, boolean, number, string)
math.ncr(n, r)
(function)- Evaluates inputs and returns the combitorial
- Parameters:
n
The input value (number, string)r
The second input value (number, string)
- Returns: nCr(n, r) (number)
math.ng(frame)
(function)- Evaluates inputs and returns the nearly guaranteed value
- Parameter:
frame
Inputs (table) - Returns: Nearly guaranteed range of inputs (string)
math.npr(n, r)
(function)- Evaluates inputs and returns the permutation
- Parameters:
n
The input value (number, string)r
The second input value (number, string)
- Returns: nPr(n, r) (number)
math.percentage(num)
(function)- Evaluates inputs and returns as a percent
- Parameter:
num
The input value (number) - Returns: number represented as a percentage (string)
math.pow(base, exponent)
(function)- Evaluates inputs and returns the power of one to the other
- Parameters:
base
The input value (number, string)exponent
The second input value (number, string)
- Returns: baseexponent (number)
math.rad(num)
(function)- Evaluates input and converts into radians
- Parameter:
num
The input value (number, string) - Returns: rad(num) (number)
math.rand(low, upp)
(function)- Evaluates input and converts into radians
- Parameters:
low
The lower bound of random values | default 0 (number, string; optional)upp
The upper bound of random values | default 1 or low if it exists (number, string; optional)frame.seed
The seed to randomize from | default current OS time (number, string; optional)
- Returns:
- rand() [0 - 1] (number)
- rand(low) [0 - low] (number)
- rand(low, upp) [low - upp] (number)
- rand(seed = 0) (number)
- etc. (number)
math.replace(str)
(function)- Replaces and deletes all non-expression characters in a string
- Parameter:
str
expression (string) - Returns: An evaluatable expression (string)
math.replaceWithSymbol(str)
(function)- Replaces constants with their symbol
- Parameter:
str
expression (string) - Returns: #e, #gamma, #phi, and #pi replaced with e, γ, φ, and π (string)
math.round(num, multiple, percent, degree)
(function)- Evaluates input and rounds to specified multiple
- Parameters:
num
The input value (number, string)multiple
The multiple to round to | default 0.0001 (number, string; optional)percent
Convert input from decimal to percentage | default false (boolean; optional)degree
Convert input into degrees | default false (boolean; optional)
- Returns:
- round(num) (string)
- round(num, 0.125) (string)
- round(num, "", true, false) (string)
- etc. (string)
math.sin(num)
(function)- Evaluates input and returns the sin
- Parameter:
num
The input value (number, string) - Returns: sin(num) (number)
math.sinh(num)
(function)- Evaluates input and returns the sinh
- Parameter:
num
The input value (number, string) - Returns: sinh(num) (number)
math.sqrt(num)
(function)- Evaluates input and returns the sqrt
- Parameter:
num
The input value (number, string) - Returns: sqrt(num) (number)
math.sub(n, m)
(function)- Evaluates inputs and returns the difference
- Parameters:
n
An input value (table, boolean, number, string)m
A second input value (table, boolean, number, string)
- Returns: sub(n, m) (table, boolean, number, string)
math.sum(nums)
(function)- Evaluates inputs and returns the summation
- Parameter:
nums
inputs (table) - Returns:
- sum(num1, num2, num3, ...) (number)
- sum(nums) (number)
math.tan(num)
(function)- Evaluates input and returns the tan
- Parameter:
num
The input value (number, string) - Returns: tan(num) (number)
math.tanh(num)
(function)- Evaluates input and returns the tanh
- Parameter:
num
The input value (number, string) - Returns: tanh(num) (number)
math.trunc(num)
(function)- Evaluates input and returns the truncation
- Parameter:
num
The input value (number, string) - Returns: trunc(num) (number)
- Created with Docbunto
See Also