Operator ** (Exponent)

Raises a number to the power of another number

Usage

base ** exponent

Parameters

base

(Required) The base number to be raised

exponent

(Required) The exponent to which the base number is raised

Examples

Example With these variables Result

2 ** 3

(None)

8

10 ** 2

(None)

100

a ** b

a is 5
b is 4

625

-5 ** 2

(None)

-25

10 ** 2 ** 0

(None)

10

More information

Multiple operators can be used. The order of operation is the same as in mathematics:

  • content of parentheses is evaluated first
  • then exponents are evaluated, from right to left
  • then multiplication and division are evaluated, from left to right
  • the remaining operators are then applied from left to right

Compared to Excel

Excel uses ^ for exponentiation. DocuMold doesn’t because Excel’s ^ has unexpected behaviours. Using ** instead helps to highlight differences compared to Excel.

Here are Excel’s unexpected behaviours:

  • -1 ^ 2 gives 1. Mathematics and most programming languages say it should be -1. The lone minus is a shortcut for -1 * and exponentiation must be done before multiplication.
  • 2 ^ 2 ^ 0 gives 1. Mathematics and most programming languages say it should be 2. Exponents are supposed to be evaluated from the right (so 2 ^ (2 ^ 0) -> 2 ^ 1 => 2), but Excel does it from the left (so (2 ^ 2) ^ 0 -> 4 ^ 0 => 1).

DocuMold’s ** doesn’t have to unexpected behaviours.

Reminders

A text containing digits is not handled as a number. To have an actual number:

  • use the @NUMBER_QUESTION to set the variable
  • write a numeric value directly in the code without quotes, ex: age >= 18
  • use a function which converts to a number: NUMBER(text_containing_numbers)
  • use a function which returns a number: FIND("world", "hello everybody")

See also