abs
ErrorsCollection

abs

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

From type/Numeric

See Original text in context

multi sub    abs(Numeric:D  --> Real:D)
multi method abs(Numeric:D: --> Real:D)

Returns the absolute value of the number.

From type/Cool

See Original text in context

sub abs(Numeric() $x)
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␤»

From type/Complex

See Original text in context

method abs(Complex:D: --> Num:D)
multi sub abs(Complex:D $z --> Num:D)

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