Go forward to Concatenation.
Go backward to Variables.
Go up to Expressions.
Arithmetic Operators
====================
The `awk' language uses the common arithmetic operators when
evaluating expressions. All of these arithmetic operators follow normal
precedence rules, and work as you would expect them to. This example
divides field three by field four, adds field two, stores the result
into field one, and prints the resulting altered input record:
awk '{ $1 = $2 + $3 / $4; print }' inventory-shipped
The arithmetic operators in `awk' are:
`X + Y'
Addition.
`X - Y'
Subtraction.
`- X'
Negation.
`+ X'
Unary plus. No real effect on the expression.
`X * Y'
Multiplication.
`X / Y'
Division. Since all numbers in `awk' are double-precision
floating point, the result is not rounded to an integer: `3 / 4'
has the value 0.75.
`X % Y'
Remainder. The quotient is rounded toward zero to an integer,
multiplied by Y and this result is subtracted from X. This
operation is sometimes known as "trunc-mod." The following
relation always holds:
b * int(a / b) + (a % b) == a
One possibly undesirable effect of this definition of remainder is
that `X % Y' is negative if X is negative. Thus,
-17 % 8 = -1
In other `awk' implementations, the signedness of the remainder
may be machine dependent.
`X ^ Y'
`X ** Y'
Exponentiation: X raised to the Y power. `2 ^ 3' has the value 8.
The character sequence `**' is equivalent to `^'. (The POSIX
standard only specifies the use of `^' for exponentiation.)