Exponentiation
Keywords: pame

Subsections

- Exercises

#
Exponentiation

If you want to compute the value of `3*3*3*3` you can do so using the multiplication operator, but it would be clearer and faster if you used the exponentiation operator `**`. The mode of its left operand can be either `REAL` or `INT`, but its right operand must have mode `INT`. If both its operands have the mode `INT`, the yield will have mode `INT` (in this case the right operand must not be negative), otherwise the yield will have mode `REAL`. Thus the formula `3**4` yields the value `81`, but `3.0**4` yields the value `81.0`. Its priority is 8. In a formula involving exponentiation as well as multiplication or division, the exponentiation is elaborated first. For example, the formula `3*2**4` yields `48`, not `1296`.

Every dyadic operator has a priority of between 1 and 9 inclusive, and all monadic operators bind more tightly than all dyadic operators. For example, the formula `-2**2` yields `4`, not `-4`. Here the monadic minus is elaborated first, followed by the exponentiation.

## Exercises

2.8
  Given these declarations:

         INT two = 2, m2 = -2;
         REAL x = 3.0 / 2.0, y = 1.0

  what is the value and mode yielded by the following formulæ? Ans
  (a)
    `two ** -m2`

  (b)
    `x ** two + y ** two`

  (c)
    `3 * m2 ** two`