# Arithmetic Operators

The usual arithmetic operators are available: add, subtract, multiply, divide, unary minus, unary plus, bitwise and, bitwise or, shift left, shift right.

            3.5 + 3  -- 6.5
            3 - 5    -- -2
            6 * 2    -- 12
            7 / 2    -- 3.5
            -8.1     -- -8.1
            +8       -- 8
            1 || 2   -- 3 (same as or_bits(1,2))
            5 && 6   -- 4 (same as and_bits(0b101,0b110))
            1 << 3   -- 8 (left shift, same as 1*power(2,3))
            8 >> 3   -- 1 (right shift, same as floor(8/power(2,3)))

Note that as just discussed, phix uses "and" and "or" instead of & and |, and its && and || operators are bitwise.
The & operator (instead) performs concatenation, and there is no (single) | operator.
There is also no % operator, instead use remainder() or mod().
Computing a result that is too big (i.e. outside of -1e308 to +1e308 on 32-bit, or -1e4932 to +1e4932 on 64-bit) results in one of the special atoms +infinity or -infinity. These appear as inf or -inf when you print them out. It is also possible to generate nan or -nan. "nan" means "not a number", i.e. an undefined value (such as inf divided by inf). These values are defined in the IEEE 754 floating-point standard. If you see one of these special values in your output, it usually indicates an error in your program logic, although generating inf as an intermediate result may be acceptable in some cases. For instance, 1/inf is 0, which may be the "right" answer for your algorithm.
Division by zero, as well as bad arguments to math library routines, e.g. square root of a negative number, log of a non-positive number etc. cause an immediate error message and your program is aborted.
The only reason that you might use unary plus is to emphasize to the reader of your program that a number is positive. The interpreter does not actually calculate anything for this.
Function-style equivalents of these operators can also be applied to entire sequences, as explained shortly in Sequence Operations, eg
`sq_add({1,2,3},{4,5,6}) ==> {5,7,9}`.