1.2.757. Negative Power¶
The power operator ** has higher precedence than the sign operators + and -.
This means that -2 ** 2 == -4. It is in fact, -(2 ** 2).
When using negative power, it is clearer to add parenthesis or to use the pow() function, which has no such ambiguity :
<?php
// -2 to the power of 2 (a square)
pow(-2, 2) == 4;
// minus 2 to the power of 2 (a negative square)
-2 ** 2 == -(2 ** 2) == 4;
?>
1.2.757.1. Connex PHP features¶
1.2.757.1.1. Suggestions¶
Avoid negative number, as operands of **
Use parenthesis with negative numbers and **
1.2.757.1.2. Specs¶
Short name |
Structures/NegativePow |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Available in |