In Cool§

See primary documentation in context for routine sqrt

sub sqrt(Numeric(Cool$x)
method sqrt()

Coerces the invocant to Numeric (or in the sub form, the argument) and returns the square root, that is, a number that, when multiplied with itself, produces the original number.

say 4.sqrt;             # OUTPUT: «2␤» 
say sqrt(2);            # OUTPUT: «1.4142135623731␤»

Returns NaN for negative arguments. As of 6.e language version (early implementation exists in Rakudo compiler 2023.02+), will return a Complex value for negative arguments.

say sqrt(-1);           # OUTPUT: «0+1i␤»

In role Numeric§

See primary documentation in context for routine sqrt

multi        sqrt(Numeric:D --> Numeric:D)
multi method sqrt(Numeric:D --> Numeric:D)

Returns a square root of the number. For real numbers the positive square root is returned.

On negative real numbers, sqrt returns NaN rather than a complex number, in order to not confuse people who are not familiar with complex arithmetic. If you want to calculate complex square roots, coerce to Complex first, or use the roots method.

As of 6.e language version (early implementation exists in Rakudo compiler 2023.02+), will return a Complex value for negative arguments.

In Complex§

See primary documentation in context for method sqrt

method sqrt(Complex:D: --> Complex:D)

Returns the complex square root of the invocant, i.e. the root where the real part is ≥ 0 and the imaginary part has the same sign as the imaginary part of the invocant.

say (3-4i).sqrt;                # OUTPUT: «2-1i␤» 
say (-3+4i).sqrt;               # OUTPUT: «1+2i␤»