Roots of unity

Raku has a built-in function cis which returns a unitary complex number given its phase. Raku also defines the tau = 2*pi constant. Thus the k-th n-root of unity can simply be written cis(k*τ/n).

constant n = 10;
for ^n -> \k {
    say cis(k*τ/n);
}

Output:

1+0i
0.809016994374947+0.587785252292473i
0.309016994374947+0.951056516295154i
-0.309016994374947+0.951056516295154i
-0.809016994374947+0.587785252292473i
-1+1.22464679914735e-16i
-0.809016994374948-0.587785252292473i
-0.309016994374948-0.951056516295154i
0.309016994374947-0.951056516295154i
0.809016994374947-0.587785252292473i

Alternately, you could use the built-in .roots method to find the nth roots of any number.

.say for 1.roots(9)

Output:

Last updated

Was this helpful?