Mathematical Operators
Mathematical operators are special symbols used to perform various operations (such as mathematical and bitwise operations).
| Operator | Description | Example | ||||
|---|---|---|---|---|---|---|
| + | Addition | Add 3 to 2. 5 is returned.
| ||||
| - | Subtraction | Subtract 3 from 2. -1 is returned.
| ||||
| * | Multiplication | Multiply 2 by 3. 6 is returned.
| ||||
| / | Division (The result is not rounded.) | Divide 4 by 2. 2 is returned.
Divide 4 by 3. 1.3333333333333333 is returned.
| ||||
| +/- | Positive/Negative | Perform operations with negative numbers.
| ||||
| % | Modulo (remainder) | Calculate the remainder of two numbers divided by each other. 5%4=1 (remainder when dividing 5 by 4)
| ||||
| @ | Absolute value | Obtain the absolute value of -5.0.
| ||||
| ^ | Power (exponentiation) | In MySQL-compatible mode, this operator means exclusive OR. For details, see the operator # in Bit String Functions and Operators. Calculate 2 raised to the power of 3. 8 is returned.
| ||||
| |/ | Square root | Calculate the square root of 25. 5 is returned.
| ||||
| ||/ | Cubic root | Calculate the cubic root of 27. 3 is returned.
| ||||
| ! | Factorial | Calculate the factorial of 5. 120 is returned.
| ||||
| !! | Factorial (prefix operator) | Calculate the factorial of 5. 120 is returned.
| ||||
| & | Binary AND | Perform a bitwise AND on 91 and 15. 11 is returned.
| ||||
| | | Binary OR | Perform a bitwise OR on 32 and 3. 35 is returned.
| ||||
| # | Binary XOR | Perform a bitwise XOR on 17 and 5. 20 is returned.
| ||||
| ~ | Binary NOT | Perform a bitwise NOT on 1. -2 is returned.
| ||||
| << | Binary shift left | Shift the binary representation of 1 (for example, 00000001) to the left by four digits and then convert it to a decimal number. 16 is returned.
| ||||
| >> | Binary shift right | Shift the binary representation of 8 (for example, 00001000) to the right by two digits and then convert it to a decimal number. 2 is returned.
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.