模組:Complex Number/Calculate/Operators
外观
![]() | 此模块被引用於約12,000個頁面。 為了避免造成大規模的影響,所有對此模块的編輯應先於沙盒或測試樣例上測試。 測試後無誤的版本可以一次性地加入此模块中,但是修改前請務必於討論頁發起討論。 模板引用數量會自動更新。 |
語法 | 名稱 | 元數 | 說明 | 優先 | 範例 | 效果 | math輸出 |
---|---|---|---|---|---|---|---|
基礎算术 | |||||||
e |
2 | 當e左鄰一實數、右鄰一整數時,則為科學記號,以 256e-3 為例,其代表的結果為。要注意的是左邊的數必為單一實數、右邊的數必為整數,可為負數,且中間不能有空格。 |
∞ | 12.3e4 |
|||
() |
1 | 改變運算優先順序 |
∞ | 2*(2+3) |
|||
布尔代数 | |||||||
and |
2 | 邏輯且的字母模式。使用時須與前後文各間隔至少一個空格 |
5 | (1=1) and (1=2) |
|||
nand |
2 | 邏輯與非的字母模式。使用時須與前後文各間隔至少一個空格 |
5 | (1=1) nand (1=2) |
|||
or |
2 | 邏輯或的字母模式。使用時須與前後文各間隔至少一個空格 |
4 | (1=1) or (1=2) |
|||
nor |
2 | 邏輯或非的字母模式。使用時須與前後文各間隔至少一個空格 |
4 | (1=1) nor (1=2) |
|||
xor |
2 | 邏輯異或的字母模式。使用時須與前後文各間隔至少一個空格 |
4 | (1=1) xor (1=2) |
|||
xnor |
2 | 邏輯若且唯若的字母模式。使用時須與前後文各間隔至少一個空格 |
4 | (1=1) xnor (1=2) |
|||
not |
1 | 邏輯非的字母模式。使用時須與前後文各間隔至少一個空格 |
13 | not (1=2) |
|||
数值修约 | |||||||
round |
2 | round 的運算子模式,會將一數四捨五入到指定的位數。使用時須與前後文各間隔至少一個空格 |
8 | π round 6 |
|||
複變 | |||||||
i |
1 | 表達純虛數 |
∞ | 3i |
|||
技術性 | |||||||
return |
1 | 返回數值。需注意return後方必須跟著一個數值或表達式,否則會變成未定義行為而出現預期外的結果。 |
2 | return 7;8 |
|||
三角函数 | |||||||
° |
1 | 用於表示角度單位的符號。 |
10 | 180° |
|||
π |
1 | 表示圓周率。 |
10 | 3π |
local p={}
p.symbol_table = {
['+'] = { propetry="op", multp = true, count = 2, priority=6, ppriority=6, calc=function(a,b,c,d)return d(a)+d(b) end},
["+ "] = { propetry="op", count = 1, priority=10, ppriority=10, calc=function(a,c,d)return d(a) end},
['-'] = { propetry="op", multp = true, count = 2, priority=6, ppriority=6, calc=function(a,b,c,d)return d(a)-d(b) end},
["- "] = { propetry="op", count = 1, priority=10, ppriority=10, calc=function(a,c,d)return -d(a) end},
['*'] = { propetry="op", multp = true, count = 2, priority=7, ppriority=7, calc=function(a,b,c,d)return d(a)*d(b) end},
["* "] = { propetry="op", count = 1, priority=10, ppriority=10, calc=function(a,c,d) if type(c.conjugate)==type(function()end) then return c.conjugate(d(a))else return d(a)end end},
['/'] = { propetry="op", count = 2, priority=7, ppriority=7, calc=function(a,b,c,d)return d(a)/d(b) end},
['%'] = { propetry="op", count = 2, priority=7, ppriority=7, calc=function(a,b,c,d)return d(a)%d(b) end},
['^'] = { propetry="op", count = 2, priority=9, ppriority=8, calc=function(a,b,c,d)return c.pow(d(a),d(b)) end},
[','] = { propetry="op", count = 2, priority=1, ppriority=1 },
['='] = { propetry="op", count = 2, priority=3, ppriority=3, calc=function(a,b,c,d)return type(c.matheq)==type(function()end)and c.matheq(d(a),d(b))or d(d(a)==d(b)and 1 or 0)end},
['≠'] = { propetry="op", count = 2, priority=3, priority=3, calc=function(a,b,c,d)return type(c.mathneq)==type(function()end)and c.mathneq(d(a),d(b))or d(d(a)~=d(b)and 1 or 0)end},
['←'] = { propetry="op", count = 2, priority=5, ppriority=5, calc=function(a,b,c,d)return type(c.mathdef)==type(function()end)and c.mathdef(d(a),d(b))or b end},
['>'] = { propetry="op", count = 2, priority=4, ppriority=4, calc=function(a,b,c,d)
if type(c.mathgt)==type(function()end) then return c.mathgt(d(a),d(b)) end
if c.abs(c.nonRealPart(d(a))) > 1e-14 or c.abs(c.nonRealPart(d(b))) > 1e-14 then return 0 end
return d(c.re(d(a))>c.re(d(b))and 1 or 0)
end},
['<'] = { propetry="op", count = 2, priority=4, ppriority=4, calc=function(a,b,c,d)
if type(c.mathlt)==type(function()end) then return c.mathlt(d(a),d(b)) end
if c.abs(c.nonRealPart(d(a))) > 1e-14 or c.abs(c.nonRealPart(d(b))) > 1e-14 then return 0 end
return d(c.re(d(a))<c.re(d(b))and 1 or 0)
end},
['≥'] = { propetry="op", count = 2, priority=4, ppriority=4, calc=function(a,b,c,d)
if type(c.mathgteq)==type(function()end) then return c.mathgteq(d(a),d(b)) end
if c.abs(c.nonRealPart(d(a))) > 1e-14 or c.abs(c.nonRealPart(d(b))) > 1e-14 then return 0 end
return d(c.re(d(a))>=c.re(d(b))and 1 or 0)
end},
['≤'] = { propetry="op", count = 2, priority=4, ppriority=4, calc=function(a,b,c,d)
if type(c.mathlteq)==type(function()end) then return c.mathlteq(d(a),d(b)) end
if c.abs(c.nonRealPart(d(a))) > 1e-14 or c.abs(c.nonRealPart(d(b))) > 1e-14 then return 0 end
return d(c.re(d(a))<=c.re(d(b))and 1 or 0)
end},
['&'] = { propetry="op", count = 2, priority=4, ppriority=4, calc=function(a,b,c,d)
if type(c.mathand)==type(function()end) then return c.mathand(d(a),d(b)) end
return d(((c.abs(d(a)) > 1e-14) and (c.abs(d(b)) > 1e-14))and 1 or 0)
end},
['|'] = { propetry="op", count = 2, priority=4, ppriority=4, calc=function(a,b,c,d)
if type(c.mathor)==type(function()end) then return c.mathor(d(a),d(b)) end
return d(((c.abs(d(a)) > 1e-14) or (c.abs(d(b)) > 1e-14))and 1 or 0)
end},
['~'] = { propetry="op", count = 1, priority=10, ppriority=10, calc=function(a,c,d)
if type(c.mathnot)==type(function()end) then return c.mathnot(d(a)) end
return d((not(c.abs(d(a)) > 1e-14))and 1 or 0)
end},
}
return p