September 2017
Beginner
402 pages
9h 52m
English
The abs method returns the absolute value. In the following example, the method is called on a variable:
my $x = -42;say $x.abs; # 42
To call it on a value, parentheses are needed for negative values. Otherwise, the unary minus operator (see more in Chapter 4, Working with Operators) will be applied to the result of calling the abs method:
say (-42).abs; # 42say -42.abs; # -42