Módulu:Math/usu
Esta ye la páxina de documentación pa Módulu:Math
Esti módulu ufre cierta cantidá de funciones matemátiques. Este funciones puen usase dende #invoke o dende otros módulos en Lua.
Usu dende otros módulos en Lua
[editar la fonte]To use the module from normal wiki pages, no special preparation is needed. If you are using the module from another Lua module, first you need to load it, like this:
local mm = require('Module:Math')
(The mm
variable stands for Module Math; you can choose something more descriptive if you prefer.)
Most functions in the module have a version for Lua and a version for #invoke. It is possible to use the #invoke functions from other Lua modules, but using the Lua functions has the advantage that you do not need to access a Lua frame object. Lua functions are preceded by _
, whereas #invoke functions are not.
random
[editar la fonte]0.63112439011742 0.43813727863046 0.5621699027541
mm._random()
mm._random(max_value)
mm._random(min_value, max_value)
Generates a random number.
- If no arguments are specified, the number produced is greater than or equal to 0 and less than 1.
- If one argument is provided, the number produced is an integer between 1 and that argument. The argument must be a positive integer.
- If two arguments are provided, the number produced is an integer between the first and second arguments. Both arguments must be integers, but can be negative.
This function will not work properly for numbers less than -2^32 and greater than 2^32 - 1 (although this may vary by hardware). If you need to use numbers outside of this range, it is recommended that you use Módulu:Random.
order
[editar la fonte]Error de formatéu: orde de magnitú na entrada paez que nun ye numbéricu
mm._order(n)
Determines the order of magnitude of a number.
precision
[editar la fonte]Error de formatéu: la entrada de precision paez non numbérica Error de formatéu: la entrada de precision paez non numbérica
mm._precision(number_string)
Detemines the precision of a number. For example, for "4" it will return "0", for "4.567" it will return "3", and for "100" it will return "-2".
The function attempts to parse the string representation of the number, and detects whether the number uses E notation. For this reason, when called from Lua, very large numbers or very precise numbers should be directly input as strings to get accurate results. If they are input as numbers, the Lua interpreter will change them to E notation and this function will return the precision of the E notation rather than that of the original number. This is not a problem when the number is called from #invoke, as all input from #invoke is in string format.
max
[editar la fonte]Error de Lua en Módulu:Math na llinia 209: attempt to call global 'binary_fold' (a nil value).
mm._max(v1, v2, v3, ...)
Returns the maximum value from the values specified. Values that cannot be converted to numbers are ignored.
min
[editar la fonte]Error de Lua en Módulu:Math na llinia 234: attempt to call global 'binary_fold' (a nil value).
mm._min(v1, v2, v3, ...)
Returns the minimum value from the values specified. Values that cannot be converted to numbers are ignored.
average
[editar la fonte]Error de Lua en Módulu:Math na llinia 258: attempt to call global 'fold' (a nil value).
mm._average(v1, v2, v3, ...)
Returns the average of the values specified. (More precisely, the value returned is the arithmetic mean.) Values that cannot be converted to numbers are ignored.
round
[editar la fonte]Error de formatéu: la entrada de round paez non numbérica Error de formatéu: la entrada de round paez non numbérica
mm._round(value, precision)
Rounds a number to the specified precision.
mod
[editar la fonte]Error de formatéu: el primer argumentu de mod paez non numbéricu
mm._mod(x, y)
Gets x
modulo y
, or the remainder after x
has been divided by y
. This is accurate for integers up to 2^53; for larger integers Lua's modulo operator may return an erroneous value. This function deals with this problem by returning 0
if the modulo given by Lua's modulo operator is less than 0 or greater than y
.
gcd
[editar la fonte]Error de Lua en Módulu:Math na llinia 360: attempt to call global 'fold' (a nil value).
mm._gcd(v1, v2, ...)
Finds the greatest common divisor of the values specified. Values that cannot be converted to numbers are ignored.
precision_format
[editar la fonte]Error de formatéu: entrada inválida al redondiar
mm._precision_format(value_string, precision)
Rounds a number to the specified precision and formats according to rules originally used for {{Rnd}}. Output is a string.
cleanNumber
[editar la fonte]local number, number_string = mm._cleanNumber(number_string)
A helper function that can be called from other Lua modules, but not from #invoke. This takes a string or a number value as input, and if the value can be converted to a number, cleanNumber returns the number and the number string. If the value cannot be converted to a number, cleanNumber returns nil, nil
.