> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/perl6-rosettacode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/perl6-rosettacode/programming_tasks/r/roots_of_unity.md).

# 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)`.

```perl
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.

```perl
.say for 1.roots(9)
```

#### Output:

```
1+0i
0.766044443118978+0.6427876096865393i
0.17364817766693041+0.984807753012208i
-0.4999999999999998+0.8660254037844387i
-0.9396926207859083+0.3420201433256689i
-0.9396926207859084-0.34202014332566866i
-0.5000000000000004-0.8660254037844384i
0.17364817766692997-0.9848077530122081i
0.7660444431189778-0.6427876096865396i
```
