The purpose of this task is to explore working with   complex numbers.



Task

Given   n,   find the   nth   roots of unity.




PI2:=(0.0).pi*2;
foreach n,i in ([1..9],n){
   c:=s:=0;
   if(not i)         c =  1;
   else if(n==4*i)   s =  1;
   else if(n==2*i)   c = -1;
   else if(3*n==4*i) s = -1;
   else a,c,s:=PI2*i/n,a.cos(),a.sin();
 
   if(c) print("%.2g".fmt(c));
   print( (s==1 and "i") or (s==-1 and "-i" or (s and "%+.2gi" or"")).fmt(s));
   print( (i==n-1) and "\n" or ",  ");
}