Documentation for routine roots

Documentation for routine roots, assembled from the following types:

class Cool

From Cool

(Cool) routine roots

Defined as:

multi sub roots(Numeric(Cool$xInt(Cool$n)
multi method roots(Int(Cool$n)

Coerces the first argument (and in method form, the invocant) to Numeric and the second ($n) to Int, and produces a list of $n Complex $n-roots, which means numbers that, raised to the $nth power, approximately produce the original number.

For example

my $original = 16;
my @roots = $original.roots(4);
say @roots;
for @roots -> $r {
    say abs($r ** 4 - $original);

produces this output:

2+0i 1.22464679914735e-16+2i -2+2.44929359829471e-16i -3.67394039744206e-16-2i

role Numeric

From Numeric

(Numeric) method roots

multi method roots(Numeric:D: Int:D $n --> Positional)

Returns a list of the $n complex roots, which evaluate to the original number when raised to the $nth power.