Skip to content

Commit 5a5b428

Browse files
authored
Document behaviour of -1² in Traps
Closes #971
1 parent 758bcb8 commit 5a5b428

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/Language/traps.pod6

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,21 @@ statements in other languages like C<return>, C<last> and many others.
334334
}
335335
say f; # OUTPUT«True␤»
336336
337+
=head2 Exponentiation Operator and Prefix Minus
338+
339+
say -1²; # -1
340+
say -1**2; # -1
341+
342+
When performing a
343+
L<regular mathematical calculation|http://www.wolframalpha.com/input/?i=-1%C2%B2>,
344+
the power takes precedence over the minus; so C<-1²> can be written as C<-(1²)>.
345+
Perl 6 matches these rules of mathematics and the precedence of C<**> operator is
346+
tighter than that of the prefix C<->. If you wish to raise a negative number
347+
to a power, use parentheses:
348+
349+
say (-1)²; # -1
350+
say (-1)**2; # -1
351+
337352
=head1 Subroutine and method calls
338353
339354
Subroutine and method calls can be made using one of two forms:

0 commit comments

Comments
 (0)