Documentation for routine sqrt
assembled from the following pages:
Class: Numeric §
From Numeric
(Numeric) routine sqrt §
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, 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.
Class: Complex §
From Complex
(Complex) method sqrt §
Defined as:
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»
Class: Cool §
From Cool
(Cool) routine sqrt §
Defined as:
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»