The analyzer has detected a binary expression that was potentially intended as exponentiation. The operator ^ was used for this operation, but in reality, ^ performs a bitwise exclusive "OR" operation.
The operator ^ performs exponentiation in some programming languages, such as Basic, R, and Haskell. In Go, however, ^ computes the bitwise exclusive "OR" of two operands—that is, a bitwise sum modulo 2. In Go, to raise a number to a power, use the math.Pow function. Another option is to use the left bitwise shift operator if a number is multiplied by 2 to the power of N.
The example:
x := 2 ^ 16
In this example, the expression evaluates to 18 rather than 65536, which is 2 to the power of 16. To get the power of 2, use the left bitwise shift operator.
The fixed code:
x := 1 << 16
This diagnostic rule is classified as:
You can look at examples of errors detected by the V8015 diagnostic. |
Was this page helpful?