Modulo:Math/sandbox: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
n |
Nessun oggetto della modifica |
||
(13 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 467:
-- PERCENTUALE CON DUE CIFRE DECIMALI MOSTRATE
function wrap.
local x = args[1]
local y = args[2]
local round = args.round
local precision = args.precision
Line 477 ⟶ 476:
yesno = require('Module:Yesno')
end
return p.
end
function p.
if y == nil or y == "" then
return err("Empty divisor")
Line 503 ⟶ 502:
end
--
function wrap.
local x = args[1]
local y = args[2]
Line 513 ⟶ 512:
yesno = require('Module:Yesno')
end
return p.
end
function p.
if y == nil or y == "" then
return err("Empty divisor")
Line 544 ⟶ 543:
---SOMMA
function wrap.
return p.
end
function p.
local
if not
return 0
else
return
end
end
---SOTTRAZIONE
function wrap.sottrazione(args)
return p._sottrazione(unpackNumberArgs(args))
end
function p._sottrazione(...)
local sottrazione, count = fold((function(a, b) return a - b end), ...)
if not sottrazione then
return 0
else
return sottrazione
end
end
--VAR
function wrap.var(args)
local x = args[1]
local y = args[2]
local round = args.round
local precision = args.precision
local precision_format = args.precision_format
if not yesno then
yesno = require('Module:Yesno')
end
return p._var(x, y, yesno(round), precision, precision_format)
end
function p._var(x, y, round, precision, precision_format)
if y == nil or y == "" then
return err("Empty divisor")
elseif not tonumber(y) then
if type(y) == 'string' and string.sub(y, 1, 1) == '<' then
return y
else
return err("Not a number: " .. y)
end
elseif x == nil or x == "" then
return err("Empty dividend")
elseif not tonumber(x) then
if type(x) == 'string' and string.sub(x, 1, 1) == '<' then
return x
else
return err("Not a number: " .. x)
end
else
local z = string.format((y-x)/y*100)
return p._precision_format(z, 2)
end
end
--MEDIA
function wrap.media(args)
return p._media(unpackNumberArgs(args))
end
function p._media(...)
local vals = makeArgArray(...)
local count = #vals
table.sort(vals)
if count == 0 then
return 0
end
if p._mod(count, 2) == 0 then
return (vals[count/2] + vals[count/2+1])/2
else
return vals[math.ceil(count/2)]
end
end
--DIV
function wrap.divide(args)
local x = args[1]
local y = args[2]
local round = args.round
local precision = args.precision
if not yesno then
yesno = require('Module:Yesno')
end
return p._divide(x, y, yesno(round), precision)
end
function p._divide(x, y, round, precision)
if y == nil or y == "" then
return err("Empty divisor")
elseif not tonumber(y) then
if type(y) == 'string' and string.sub(y, 1, 1) == '<' then
return y
else
return err("Not a number: " .. y)
end
elseif x == nil or x == "" then
return err("Empty dividend")
elseif not tonumber(x) then
if type(x) == 'string' and string.sub(x, 1, 1) == '<' then
return x
else
return err("Not a number: " .. x)
end
else
local z = x / y
if round then
return p._round(z, 0)
elseif precision then
return p._round(z, precision)
else
return z
end
end
end
|