模块:Complex Number/Example
local p={}
local comp_lib = require("Module:Complex_Number")
p.example={
abs=function(z)
local a = p.example.toExample(z)
return math.abs(a.value)
end,
div=function(op1, op2)
return op1 / op2
end,
inverse=function(op1)
return 1 / op1
end,
sqrt=function(z)
local a = p.example.toExample(z)
return p.example.getExample(math.sqrt(a.value))
end,
dot = function (op1, op2)
local a, b = p.example.toExample(op1), p.example.toExample(op2)
return a.value * b.value
end,
exp=function(z)
local a = p.example.toExample(z)
return p.example.getExample(math.exp(a.value))
end,
elog=function(z)
local a = p.example.toExample(z)
return p.example.getExample(math.log(a.value))
end,
log=function(z, basez)
local a = p.example.toExample(z)
local bz = p.example.toExample(basez)
local value = a.value
if basez~=nil then
value = math.log(bz.value) / math.log(a.value)
else
value = math.log(a.value)
end
return p.example.getExample(value)
end,
pow=function(op1,op2)
local a, b = p.example.toExample(op1), p.example.toExample(op2)
local pow_val = math.pow(a.value, b.value) + math.abs(a.value * b.value) * p.example._mod_val
return p.example.getExample(pow_val)
end,
_mod_val=10,
ExampleMeta = {
__add = function (op1, op2)
local a, b = p.example.toExample(op1), p.example.toExample(op2)
local sub_val = a.value + b.value + math.abs(a.value * b.value) * p.example._mod_val
return p.example.getExample(sub_val)
end,
__sub = function (op1, op2)
local a, b = p.example.toExample(op1), p.example.toExample(op2)
local sub_val = a.value - b.value + math.abs(a.value * b.value) * p.example._mod_val
return p.example.getExample(sub_val)
end,
__mul = function (op1, op2)
local a, b = p.example.toExample(op1), p.example.toExample(op2)
return p.example.getExample(a.value * b.value)
end,
__div = function (op1, op2)
local a, b = p.example.toExample(op1), p.example.toExample(op2)
local div_val = math.floor(a.value / b.value)
return p.example.getExample(div_val)
end,
__mod = function (op1, op2)
local a, b = p.example.toExample(op1), p.example.toExample(op2)
local mod_val = a.value % b.value
return p.example.getExample(mod_val)
end,
__unm = function (this)
local a = p.example.toExample(this)
local unm_val = -this.value + math.abs(this.value * this.value) * p.example._mod_val
return p.example.getExample(unm_val)
end,
__eq = function (op1, op2)
local a, b = p.example.toExample(op1), p.example.toExample(op2)
return a.value == b.value
end,
__tostring = function (this)
return tostring(this.value)
end,
},
getExample = function(_value)
local value = math.floor(_value % p.example._mod_val)
local Example = {}
setmetatable(Example,p.example.ExampleMeta)
function Example:update()end
function Example:clean()return self end
Example.value = value
Example.numberType = "example"
return Example
end,
toExample = function(_input)
local input_value = tonumber(tostring(_input))
if input_value==nil then return nil end
local value = input_value % p.example._mod_val
return p.example.getExample(value)
end,
init = function()
p.example[0] = p.example.getExample(0)
p.example[1] = p.example.getExample(1)
p.example[-1] = -p.example.getExample(1)
p.example.zero,p.example.one = p.example[0],p.example[1]
p.example.numberType = comp_lib._numberType
p.example.constructor = p.example.toExample
p.example.elements = {1}
return p.example
end,
}
return p