Jump to content
Menyu yikuru
Menyu yikuru
move to sidebar
kubisa
Mayendelo
Jani likulu
Vidumbizgano vya chikaya
Vakuchitika vasono
Kusintha kuphya
Jani lililose
Wovwili
To Do
Vyakuti vinozgeke
Vinyake
Mafumbo
Mazgo ghakomi
Helpful Pages (Wovwili)
Need for Fix
Need for Review
Admin Pages
Home pages
Home templates
Kufufuza
Kufufuza
Kaonekelo
Chakupeleka
Panga akaunti
Njila
Vilwelo vyako
Chakupeleka
Panga akaunti
Njila
Pages for logged out editors
learn more
vyakulemba
Pakuchezgela
Kulemba
Module:Math/doc
Sazgapo viyowoyelo
Module
Kudumbizgana
chiTumbuka
Ŵelengani
Kulemba source
Kuona umo mayambilo
Vilwelo
Vilwelo
move to sidebar
kubisa
Vyakuchita
Ŵelengani
Kulemba source
Kuona umo mayambilo
Vya masiku ghose
Ivo vikwiza pano
Vyaku sintha
Kwezgela chinthu
Va jani lino
Penjani URL yakufupikizgika
Sangululani kodi ya QR
Kaonekelo
move to sidebar
kubisa
Chenjezgo:
Mundanjile mu akaunti yinu. Pala mulembenge chilichose IP adilesi yinu waliyose waionenge. Pala
mwanjila
mu akaunti yinu
panji
mwapanga akaunti
, vyakulemba vinu vyose viŵenge mu zina linu, na uwemi unyake.
Anti-spam check. Do
not
fill this in!
{{for|''formatting'' mathematical expressions, LATEX-style|Template:Math}} {{High-risk|1,607,000+}} {{module rating|protected}} This module provides a number of mathematical functions. These functions can be used from #invoke or from other Lua modules. == Use from other Lua modules == 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: <syntaxhighlight lang="lua"> local mm = require('Module:Math') </syntaxhighlight> (The <code>mm</code> variable stands for '''M'''odule '''M'''ath; 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 [[mw:Extension:Scribunto/Lua reference manual#Frame object|frame object]]. Lua functions are preceded by <code>_</code>, whereas #invoke functions are not. == random == {{see also|Module:Random}} {{#invoke:math|random}} {{#invoke:math|random|''max_value''}} {{#invoke:math|random|''min_value''|''max_value''}} <syntaxhighlight lang="lua"> mm._random() mm._random(max_value) mm._random(min_value, max_value) </syntaxhighlight> 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<sup>32</sup> and greater than 2<sup>32</sup> − 1. If you need to use numbers outside of this range, it is recommended that you use [[Module:Random]]. == order == {{#invoke:math|order|''n''}} <syntaxhighlight lang="lua"> mm._order(n) </syntaxhighlight> Determines the [[order of magnitude]] of a number. == precision == {{#invoke:math|precision|''n''}} {{#invoke:math|precision|x=''n''}} <syntaxhighlight lang="lua"> mm._precision(number_string) </syntaxhighlight> 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 [[Scientific notation#E notation|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 == {{#invoke:math|max|''v1''|''v2''|''v3''|...}} <syntaxhighlight lang="lua"> mm._max(v1, v2, v3, ...) </syntaxhighlight> Returns the maximum value from the values specified. Values that cannot be converted to numbers are ignored. == median == {{#invoke:math|median|''v1''|''v2''|''v3''|...}} <syntaxhighlight lang="lua"> mm._median(v1, v2, v3, ...) </syntaxhighlight> Returns the [[median]] value from the values specified. Values that cannot be converted to numbers are ignored. == min == {{#invoke:math|min|''v1''|''v2''|''v3''|...}} <syntaxhighlight lang="lua"> mm._min(v1, v2, v3, ...) </syntaxhighlight> Returns the minimum value from the values specified. Values that cannot be converted to numbers are ignored. == sum == {{#invoke:math|sum|''v1''|''v2''|''v3''|...}} <syntaxhighlight lang="lua"> mm._sum(v1, v2, v3, ...) </syntaxhighlight> Returns the sum of the values specified. Values that cannot be converted to numbers are ignored. == average == {{#invoke:math|average|''v1''|''v2''|''v3''|...}} <syntaxhighlight lang="lua"> mm._average(v1, v2, v3, ...) </syntaxhighlight> 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. == round == {{#invoke:math|round|''value''|''precision''}} {{#invoke:math|round|value=''value''|precision=''precision''}} <syntaxhighlight lang="lua"> mm._round(value, precision) </syntaxhighlight> [[Rounding|Rounds]] a number to the specified precision. Note: As of October 2019, there is a bug in the display of some rounded numbers. When trying to round a number that rounds to "n.0", like "1.02", to the nearest tenth of a digit (i.e. {{para|r|1}}), this function should display "1.0", but it unexpectedly displays "1". Use the {{para|precision_format}} parameter instead. == log10 == {{#invoke:math | log10 | ''x''}} <syntaxhighlight lang="lua"> mm._log10(x) </syntaxhighlight> Returns <code>log<sub>10</sub>(''x'')</code>, the [[logarithm]] of ''x'' using base 10. == mod == {{#invoke:math|mod|''x''|''y''}} <syntaxhighlight lang="lua"> mm._mod(x, y) </syntaxhighlight> 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<sup>53</sup>; 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>. == gcd == {{#invoke:math|gcd|''v1''|''v2''|...}} <syntaxhighlight lang="lua"> mm._gcd(v1, v2, ...) </syntaxhighlight> Finds the [[greatest common divisor]] of the values specified. Values that cannot be converted to numbers are ignored. == precision_format == {{#invoke:math|precision_format|''value_string''|''precision''}} <syntaxhighlight lang="lua"> mm._precision_format(value_string, precision) </syntaxhighlight> Rounds a number to the specified precision and formats according to rules originally used for {{tl|Rnd}}. Output is a string. Parameter <var>precision</var> should be an integer number of digits after the decimal point. Negative values are permitted. Non-integers give unexpected results. Positive values greater than the input precision add zero-padding, negative values greater than the input order can consume all digits. Formatting 8,765.567 with {{tlc|#invoke:Math|precision_format|8765.567|<var>precision</var>}} gives: {|class="wikitable" |+ !<code><var>precision</var></code>!!Result |- |style="text-align:right"|2||{{#invoke:Math|precision_format|8765.567|2}} |- |style="text-align:right"| -2||{{#invoke:Math|precision_format|8765.567|-2}} |- |style="text-align:right"|6||{{#invoke:Math|precision_format|8765.567|6}} |- |style="text-align:right"| -6||{{#invoke:Math|precision_format|8765.567|-6}} |- |style="text-align:right"|2.5||{{#invoke:Math|precision_format|8765.567|2.5}} |- |style="text-align:right"| -2.5||{{#invoke:Math|precision_format|8765.567|-2.5}} |} == divide == {{#invoke:Math|divide|''x''|''y''|''round=''|''precision=''}} <syntaxhighlight lang="lua"> mm._divide(x, y, round, precision) </syntaxhighlight> Divide x by y. * If y if not a number, it is returned. * Otherwise, if x is not a number, it is returned. * If round is true ("yes" for #invoke), the result has no decimals * Precision indicates how many digits of precision the result should have If any of the arguments contain HTML tags, they are returned unchanged, allowing any errors in calculating the arguments to the division function to be propagated to the calling template. == cleanNumber == <syntaxhighlight lang="lua"> local number, number_string = mm._cleanNumber(number_string) </syntaxhighlight> 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>. ==See also== {{Math templates}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Kuleka
Wowili wakalembelo
(julani mu windo lanyuwani)
Preview page with this template
Nkhwaska zagwiliskika apa:
Template:Aligned table
(
lemba
)
Template:C
(
lemba
)
Template:Category link
(
lemba
)
Template:Ceil
(
lemba
)
Template:Dot
(
lemba
)
Template:Endflatlist
(
lemba
)
Template:Flatlist
(
lemba
)
Template:Floor
(
lemba
)
Template:Font
(
lemba
)
Template:For
(
lemba
)
Template:Frac
(
lemba
)
Template:Fraction
(
lemba
)
Template:Fraction/styles.css
(
lemba
)
Template:High-risk
(
lemba
)
Template:High-use
(
lemba
)
Template:Hlist
(
lemba
)
Template:Hlist/styles.css
(
lemba
)
Template:Icon
(
lemba
)
Template:Large
(
lemba
)
Template:Main other
(
lemba
)
Template:Math
(
lemba
)
Template:Math templates
(
lemba
)
Template:Ml
(
lemba
)
Template:Module link
(
lemba
)
Template:Module rating
(
lemba
)
Template:Navbox
(
lemba
)
Template:Navbox with collapsible groups
(
lemba
)
Template:Navbox with columns
(
lemba
)
Template:Noitalic
(
lemba
)
Template:Noitalic/styles.css
(
lemba
)
Template:Para
(
lemba
)
Template:Pars
(
lemba
)
Template:Plainlist/styles.css
(
lemba
)
Template:See also
(
lemba
)
Template:Sfrac
(
lemba
)
Template:Sfrac/styles.css
(
lemba
)
Template:Startflatlist
(
lemba
)
Template:Str endswith
(
lemba
)
Template:Template link
(
lemba
)
Template:Template link bare
(
lemba
)
Template:Tl
(
lemba
)
Template:Tlbare
(
lemba
)
Template:Tlc
(
lemba
)
Template:Tlx
(
lemba
)
Template:Wonaniso
(
lemba
)
Template:Yesno
(
lemba
)
Template:·
(
lemba
)
Module:Aligned table
(
lemba
)
Module:Arguments
(
lemba
)
Module:Check for unknown parameters
(
lemba
)
Module:For
(
lemba
)
Module:Format link
(
lemba
)
Module:Hatnote
(
lemba
)
Module:Hatnote/styles.css
(
lemba
)
Module:Hatnote list
(
lemba
)
Module:High-use
(
lemba
)
Module:Icon
(
lemba
)
Module:Icon/data
(
lemba
)
Module:Labelled list hatnote
(
lemba
)
Module:List
(
lemba
)
Module:Math
(
lemba
)
Module:Message box
(
lemba
)
Module:Message box/configuration
(
lemba
)
Module:Message box/ombox.css
(
lemba
)
Module:Navbar
(
lemba
)
Module:Navbar/configuration
(
lemba
)
Module:Navbar/styles.css
(
lemba
)
Module:Navbox
(
lemba
)
Module:Navbox/configuration
(
lemba
)
Module:Navbox/styles.css
(
lemba
)
Module:Navbox with collapsible groups
(
lemba
)
Module:Separated entries
(
lemba
)
Module:String
(
lemba
)
Module:TableTools
(
lemba
)
Module:Transclusion count
(
lemba
)
Module:Transclusion count/data/M
(
lemba
)
Module:Unsubst
(
lemba
)
Module:Yesno
(
lemba
)
Kufufuza
Kufufuza
Kulemba
Module:Math/doc
Sazgapo viyowoyelo
Add topic