Read the source code
complex.cs
and
cmath.cs
and find out how the complex numbers and complex function are defined.
Get the two files to your box, for example,
sudo apt install wget
mkdir -p ~/ppnm/matlib/complex # or whatever name you deem indicative
cd ~/ppnm/matlib/complex
wget http://172.28.64.23:8080/prog/matlib/complex/complex.cs wget http://172.28.64.23:8080/prog/matlib/complex/cmath.cs
cmath.dll
library,
DIR = $(HOME)/ppnm/matlib/complex # or whatever your directory is cmath.dll : $(DIR)/cmath.cs $(DIR)/complex.cs mcs -target:library -out:./cmath.dll $^Note "./" (the current directory) in front of "cmath.dll".
You then link your "cmath.dll" library when compiling your
main.cs
like this,
main.exe : main.cs cmath.dll mcs -reference:cmath.dll main.cs
Calculate √-1, √i, ei, eiπ, ii, ln(i), sin(iπ) and compare (using our "approx" function) with manually calculated results (check them please before using):
√-1 = ±i, ln(i) = ln(eiπ/2) = iπ/2, √i = e½ln(i) = eiπ/4 = cos(π/4)+i sin(π/4) = 1/√2+i/√2 (and where is the second branch, you think?) ii = ei ln(i) = e-π/2 ≈ 0.208, (ii is actually real – magic, isn't it?)
Extra: add to our cmath-class the hyperbolic functions sinh, cosh of complex argument—and calculate sinh(i), cosh(i). Check that the results are correct.