3.  Expressions

      The value of an expression is printed unless the main operator is an assignment. Precedence is the same as the order of presentation here, with highest appearing first. Left or right associativity, where applicable, is discussed with each operator.

3.1.  Primitive expressions

3.1.1.  Named expressions

      Named expressions are places where values are stored. Simply stated, named expressions are legal on the left side of an assignment. The value of a named expression is the value stored in the place named.

3.1.1.1.  identifiers

      Simple identifiers are named expressions. They have an initial value of zero.

3.1.1.2.  array-name[expression]

      Array elements are named expressions. They have an initial value of zero.

3.1.1.3.  scale, ibase and obase

      The internal registers scale, ibase and obase are all named expressions. scale is the number of digits after the decimal point to be retained in arithmetic operations. scale has an initial value of zero. ibase and obase are the input and output number radix respectively. Both ibase and obase have initial values of 10.

3.1.2.  Function calls

3.1.2.1.  function-name([expression[,expression...]])

      A function call consists of a function name followed by parentheses containing a comma-separated list of expressions, which are the function arguments. A whole array passed as an argument is specified by the array name followed by empty square brackets. All function arguments are passed by value. As a result, changes made to the formal parameters have no effect on the actual arguments. If the function terminates by executing a return statement, the value of the function is the value of the expression in the parentheses of the return statement or is zero if no expression is provided or if there is no return statement.

3.1.2.2.  sqrt(expression)

      The result is the square root of the expression. The result is truncated in the least significant decimal place. The scale of the result is the scale of the expression or the value of scale, whichever is larger.

3.1.2.3.  length(expression)

      The result is the total number of significant decimal digits in the expression. The scale of the result is zero.

3.1.2.4.  scale(expression)

      The result is the scale of the expression. The scale of the result is zero.

3.1.3.  Constants

      Constants are primitive expressions.

3.1.4.  Parentheses

      An expression surrounded by parentheses is a primitive expression. The parentheses are used to alter the normal precedence.

3.2.  Unary operators

      The unary operators bind right to left.

3.2.1.  -expression

      The result is the negative of the expression.

3.2.2.  ++named-expression

      The named expression is incremented by one. The result is the value of the named expression after incrementing.

3.2.3.  --named-expression

      The named expression is decremented by one. The result is the value of the named expression after decrementing.

3.2.4.  named-expression++

      The named expression is incremented by one. The result is the value of the named expression before incrementing.

3.2.5.  named-expression--

      The named expression is decremented by one. The result is the value of the named expression before decrementing.

3.3.  Exponentiation operator

      The exponentiation operator binds right to left.

3.3.1.  expression ^ expression

      The result is the first expression raised to the power of the second expression. The second expression must be an integer. If a is the scale of the left expression and b is the absolute value of the right expression, then the scale of the result is:

      min(a×b,max(scale,a))

3.4.  Multiplicative operators

      The operators *, /, % bind left to right.

3.4.1.  expression * expression

      The result is the product of the two expressions. If a and b are the scales of the two expressions, then the scale of the result is:

      min(a+b,max(scale,a,b))

3.4.2.  expression / expression

      The result is the quotient of the two expressions. The scale of the result is the value of scale.

3.4.3.  expression % expression

      The % operator produces the remainder of the division of the two expressions. More precisely, a%b is a-a/b*b.

      The scale of the result is the sum of the scale of the divisor and the value of scale

3.5.  Additive operators

      The additive operators bind left to right.

3.5.1.  expression + expression

      The result is the sum of the two expressions. The scale of the result is the maximun of the scales of the expressions.

3.5.2.  expression - expression

      The result is the difference of the two expressions. The scale of the result is the maximum of the scales of the expressions.

3.6.  assignment operators

      The assignment operators bind right to left.

3.6.1.  named-expression = expression

      This expression results in assigning the value of the expression on the right to the named expression on the left.

3.6.2.  named-expression =+ expression

3.6.3.  named-expression =- expression

3.6.4.  named-expression =* expression

3.6.5.  named-expression =/ expression

3.6.6.  named-expression =% expression

3.6.7.  named-expression =^ expression

      The result of the above expressions is equivalent to ``named expression = named expression OP expression'', where OP is the operator after the = sign.