コンテンツにスキップ

「モジュール:Math」の版間の差分

1版 をインポートしました
en>Primefac
(typo fix)
(1版 をインポートしました)
16行目: 16行目:
local function err(msg)
local function err(msg)
-- Generates wikitext error messages.
-- Generates wikitext error messages.
return mw.ustring.format('<strong class="error">Formatting error: %s</strong>', msg)
return mw.ustring.format('<strong class="error">書式エラー: %s</strong>', msg)
end
end


117行目: 117行目:
local input_number = p._cleanNumber(input_string);
local input_number = p._cleanNumber(input_string);
if input_number == nil then
if input_number == nil then
return err('order of magnitude input appears non-numeric')
return err('order関数に渡された引数が数字ではありません')
else
else
return p._order(input_number)
return p._order(input_number)
160行目: 160行目:
input_number, input_string = p._cleanNumber(input_string);
input_number, input_string = p._cleanNumber(input_string);
if input_string == nil then
if input_string == nil then
return err('precision input appears non-numeric')
return err('precision関数に渡された引数が数字ではありません')
else
else
return p._precision(input_string)
return p._precision(input_string)
344行目: 344行目:
local precision = p._cleanNumber(args[2] or args.precision or 0)
local precision = p._cleanNumber(args[2] or args.precision or 0)
if value == nil or precision == nil then
if value == nil or precision == nil then
return err('round input appears non-numeric')
return err('round関数に渡された引数が数字ではありません')
else
else
return p._round(value, precision)
return p._round(value, precision)
382行目: 382行目:
local y = p._cleanNumber(args[2])
local y = p._cleanNumber(args[2])
if not x then
if not x then
return err('first argument to mod appears non-numeric')
return err('mod関数に渡された第1引数が数字ではありません')
elseif not y then
elseif not y then
return err('second argument to mod appears non-numeric')
return err('mod関数に渡された第2引数が数字ではありません')
else
else
return p._mod(x, y)
return p._mod(x, y)
454行目: 454行目:
-- Check for non-numeric input
-- Check for non-numeric input
if value == nil or precision == nil then
if value == nil or precision == nil then
return err('invalid input when rounding')
return err('_precision_format関数に渡された引数が不正です')
end
end


532行目: 532行目:


return formatted_num
return formatted_num
end
--[[
divide
Implements the division operator
Usage:
{{#invoke:Math | divide | x | y | round= | precision= }}
--]]
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
end


管理者、translator
2,311

回編集