Documentation for routine
sqrt assembled from the following types:
multi sub sqrt(Numeric --> Numeric)multi method sqrt(Numeric --> Numeric)
Returns a square root of the number. For real numbers the positive square root is returned.
On negative real numbers,
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
method sqrt(Complex: --> Complex)
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␤»
sub sqrt(Numeric(Cool) )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␤»