3 package
.path
= arg
[0]:sub(0, -arg
[0]:match("([^/\\]*)$"):len() - 1) .. "?.lua;" .. package
.path
4 local test
= require("test")
5 local a
= require("liba")
7 local x
= a
.complex
.new(1, 2)
8 local y
= a
.complex
.rect(2, 1)
9 local z
= a
.complex
.polar(1, math
.pi
)
10 test
.dir(getmetatable(z
))
11 test
.log(z
:proj(), z
:conj(), z
.rho
, z
.theta
)
12 z
.real
, z
.imag
= math
.pi
, math
.pi
13 test
.log("- " .. tostring(x
) .. " = " .. tostring(-x
))
14 test
.log(tostring(x
) .. " + " .. tostring(y
) .. " = " .. tostring(x
+ y
))
15 test
.log(tostring(x
) .. " - " .. tostring(y
) .. " = " .. tostring(x
- y
))
16 test
.log(tostring(x
) .. " * " .. tostring(y
) .. " = " .. tostring(x
* y
))
17 test
.log(tostring(x
) .. " / " .. tostring(y
) .. " = " .. tostring(x
/ y
))
18 test
.log("- " .. tostring(x
) .. " = " .. tostring(x
:unm()))
19 test
.log(tostring(x
) .. " + " .. tostring(y
) .. " = " .. tostring(x
:add(y
)))
20 test
.log(tostring(x
) .. " - " .. tostring(y
) .. " = " .. tostring(x
:sub(y
)))
21 test
.log(tostring(x
) .. " * " .. tostring(y
) .. " = " .. tostring(x
:mul(y
)))
22 test
.log(tostring(x
) .. " / " .. tostring(y
) .. " = " .. tostring(x
:div(y
)))
24 assert(a
.complex
.exp(z
))
26 assert(a
.complex
.log(z
))
28 assert(a
.complex
.sqrt(z
))
30 assert(a
.complex
.log2(z
))
32 assert(a
.complex
.log10(z
))
34 assert(a
.complex
.sin(z
))
36 assert(a
.complex
.cos(z
))
38 assert(a
.complex
.tan(z
))
40 assert(a
.complex
.sec(z
))
42 assert(a
.complex
.csc(z
))
44 assert(a
.complex
.cot(z
))
46 assert(a
.complex
.asin(z
))
48 assert(a
.complex
.acos(z
))
50 assert(a
.complex
.atan(z
))
52 assert(a
.complex
.asec(z
))
54 assert(a
.complex
.acsc(z
))
56 assert(a
.complex
.acot(z
))
58 assert(a
.complex
.sinh(z
))
60 assert(a
.complex
.cosh(z
))
62 assert(a
.complex
.tanh(z
))
64 assert(a
.complex
.sech(z
))
66 assert(a
.complex
.csch(z
))
68 assert(a
.complex
.coth(z
))
70 assert(a
.complex
.asinh(z
))
72 assert(a
.complex
.acosh(z
))
74 assert(a
.complex
.atanh(z
))
76 assert(a
.complex
.asech(z
))
78 assert(a
.complex
.acsch(z
))
80 assert(a
.complex
.acoth(z
))
103 ---@field __unm function
104 ---@field __add function
105 ---@field __sub function
106 ---@field __mul function
107 ---@field __div function
108 ---@field __pow function
109 ---@field __len function
110 ---@field __name string
111 ---@field __index table
112 ---@field __newindex table