sqrt
ErrorsCollection

sqrt

Synthesised documentation from type/Numeric type/Cool type/Complex

From type/Numeric

See Original text in context

multi sub    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.

From type/Cool

See Original text in context

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 non-negative number that, when multiplied with itself, produces the original number.

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

From type/Complex

See Original text in context

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␤»