Diferencies ente revisiones de «Módulu:Math/usu»

Contenido eliminado Contenido añadido
Oriciu (alderique | contribuciones)
Documentación del módulu (entamu)
 
Xqbot (alderique | contribuciones)
m Bot: Reemplace la etiqueta obsoleta <source> y el parámetro "enclose"; cambios cosméticos
 
Llinia 4:
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:
 
<sourcesyntaxhighlight lang="lua">
local mm = require('Module:Math')
</syntaxhighlight>
</source>
 
(The <code>mm</code> variable stands for '''M'''odule '''M'''ath; you can choose something more descriptive if you prefer.)
Llinia 15:
{{see also|Module:Random}}
 
&#123;{{#invoke:math|random}}
&#123;{{#invoke:math|random|''max_value''}}
&#123;{{#invoke:math|random|''min_value''|''max_value''}}
 
<sourcesyntaxhighlight lang="lua">
mm._random()
mm._random(max_value)
mm._random(min_value, max_value)
</syntaxhighlight>
</source>
 
Generates a random number.
Llinia 31:
* 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 [[ModuleMódulu:Random]].
 
== order ==
 
&#123;{{#invoke:math|order|''n''}}
 
<sourcesyntaxhighlight lang="lua">
mm._order(n)
</syntaxhighlight>
</source>
 
Determines the [[order of magnitude]] of a number.
Llinia 45:
== precision ==
 
&#123;{{#invoke:math|precision|''n''}}
&#123;{{#invoke:math|precision|x=''n''}}
 
<sourcesyntaxhighlight lang="lua">
mm._precision(number_string)
</syntaxhighlight>
</source>
 
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".
Llinia 58:
== max ==
 
&#123;{{#invoke:math|max|''v1''|''v2''|''v3''|...}}
 
<sourcesyntaxhighlight lang="lua">
mm._max(v1, v2, v3, ...)
</syntaxhighlight>
</source>
 
Returns the maximum value from the values specified. Values that cannot be converted to numbers are ignored.
Llinia 68:
== min ==
 
&#123;{{#invoke:math|min|''v1''|''v2''|''v3''|...}}
 
<sourcesyntaxhighlight lang="lua">
mm._min(v1, v2, v3, ...)
</syntaxhighlight>
</source>
 
Returns the minimum value from the values specified. Values that cannot be converted to numbers are ignored.
Llinia 78:
== average ==
 
&#123;{{#invoke:math|average|''v1''|''v2''|''v3''|...}}
 
<sourcesyntaxhighlight lang="lua">
mm._average(v1, v2, v3, ...)
</syntaxhighlight>
</source>
 
Returns the average of the values specified. (More precisely, the value returned is the [[Mean#Arithmetic mean (AM)|arithmetic mean]].) Values that cannot be converted to numbers are ignored.
Llinia 88:
== round ==
 
&#123;{{#invoke:math|round|''value''|''precision''}}
&#123;{{#invoke:math|round|value=''value''|precision=''precision''}}
 
<sourcesyntaxhighlight lang="lua">
mm._round(value, precision)
</syntaxhighlight>
</source>
 
[[Rounding|Rounds]] a number to the specified precision.
Llinia 99:
== mod ==
 
&#123;{{#invoke:math|mod|''x''|''y''}}
 
<sourcesyntaxhighlight lang="lua">
mm._mod(x, y)
</syntaxhighlight>
</source>
 
Gets <code>''x''</code> [[Modulo operation|modulo]] <code>''y''</code>, or the remainder after <code>''x''</code> has been divided by <code>''y''</code>. 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 <code>0</code> if the modulo given by Lua's modulo operator is less than 0 or greater than <code>''y''</code>.
Llinia 109:
== gcd ==
 
&#123;{{#invoke:math|gcd|''v1''|''v2''|...}}
 
<sourcesyntaxhighlight lang="lua">
mm._gcd(v1, v2, ...)
</syntaxhighlight>
</source>
 
Finds the [[greatest common divisor]] of the values specified. Values that cannot be converted to numbers are ignored.
Llinia 119:
== precision_format ==
 
&#123;{{#invoke:math|precision_format|''value_string''|''precision''}}
 
<sourcesyntaxhighlight lang="lua">
mm._precision_format(value_string, precision)
</syntaxhighlight>
</source>
 
Rounds a number to the specified precision and formats according to rules originally used for {{tl|Rnd}}. Output is a string.
 
== cleanNumber ==
 
<sourcesyntaxhighlight lang="lua">
local number, number_string = mm._cleanNumber(number_string)
</syntaxhighlight>
</source>
 
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 <code>nil, nil</code>.