Modulo:Math/sandbox: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
151 cp (discussione | contributi)
Nessun oggetto della modifica
151 cp (discussione | contributi)
Nessun oggetto della modifica
 
(5 versioni intermedie di uno stesso utente non sono mostrate)
Riga 467:
 
-- PERCENTUALE CON DUE CIFRE DECIMALI MOSTRATE
function wrap.ciaoperc(args)
local x = args[1]
local y = args[2]
Riga 476:
yesno = require('Module:Yesno')
end
return p._ciao_perc(x, y, yesno(round), precision, precision_format)
end
 
function p._ciao_perc(x, y, round, precision, precision_format)
if y == nil or y == "" then
return err("Empty divisor")
Riga 503:
 
--PERCENTUALE CON PARAMETRO PER NUMERO CIFRE DECIMALI DA MOSTRARE
function wrap.salveperk(args)
local x = args[1]
local y = args[2]
Riga 512:
yesno = require('Module:Yesno')
end
return p._salve_perk(x, y, yesno(round), precision, precision_format)
end
 
function p._salve_perk(x, y, round, precision, precision_format)
if y == nil or y == "" then
return err("Empty divisor")
Riga 572:
--VAR
function wrap.var(args)
local ax = args[1]
return p._var(unpackNumberArgs(args))
local by = args[2]
end
local round = args.round
 
local precision = args.precision
function p._var(...)
local precision_format = args.precision_format
local var, count = fold((function(a, b) return ((b-a)/a*100) end), ...)
if not var then
return 0
else
return var
end
end
 
 
--VARIAZIONE
function wrap.varia(args)
local a = args[1]
local b = args[2]
if not yesno then
yesno = require('Module:Yesno')
end
return p._varia_var(ax, by, yesno(round), precision, precision_format)
end
 
function p._varia_var(ax, by, round, precision, precision_format)
if y == nil or y == "" then
local z = (b-a)/a*100
return p._variaerr(z"Empty divisor")
elseif not tonumber(y) then
if type(y) == 'string' and string.sub(y, 1, 1) == '<' then
return 0y
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 varx
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
 
Line 620 ⟶ 626:
end
end
 
--DIV
function pwrap._vardivide(...args)
local x = args[1]
local y = args[2]
local round = args.round
local precision = args.precision
if not varyesno 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 = (b-a)x /a*100 y
if round then
return p._round(z, 0)
elseif precision then
return p._round(z, precision)
else
return z
end
end
end
 
 
--[[