routine abs
1 | class Complex |
1.1 | (Complex) method abs |
2 | class Numeric |
2.1 | (Numeric) routine abs |
3 | class Cool |
3.1 | (Cool) routine abs |
Documentation for routine abs
assembled from the following types:
class Complex
From Complex
(Complex) method abs
Defined as:
method abs(Complex: --> Num)multi sub abs(Complex --> Num)
Returns the absolute value of the invocant (or the argument in sub form). For a given complex number $z
the absolute value |$z|
is defined as sqrt($z.re * $z.re + $z.im * $z.im)
.
say (3+4i).abs; # OUTPUT: «5»# sqrt(3*3 + 4*4) == 5
class Numeric
From Numeric
(Numeric) routine abs
multi sub abs(Numeric --> Real)multi method abs(Numeric: --> Real)
Returns the absolute value of the number.
class Cool
From Cool
(Cool) routine abs
Defined as:
sub abs(Numeric() )method abs()
Coerces the invocant (or in the sub form, the argument) to Numeric and returns the absolute value (that is, a non-negative number).
say (-2).abs; # OUTPUT: «2»say abs "6+8i"; # OUTPUT: «10»