projog

4.13. ** - calculates the result of the first argument raised to the power of the second argument.

Examples

?- X is 2 ** 1.
X = 2

yes

?- X is 2 ** 2.
X = 4

yes

?- X is 2 ** 5.
X = 32

yes

?- X is 5 ** 3.
X = 125

yes

?- X is 5.0 ** 3.
X = 125.0

yes

?- X is 5 ** 3.0.
X = 125.0

yes

?- X is 5.0 ** 3.0.
X = 125.0

yes

?- X is 2 + 5 ** 3 - 1.
X = 126

yes

?- X is -2 ** 2.
X = 4

yes

Note: in some Prolog implementations the result would be 0.25

?- X is -2 ** -2.
X = 0

yes

Note: in some Prolog implementations the result would be 0.25

?- X is 2 ** -2.
X = 0

yes

?- X is 0.5 ** 2.
X = 0.25

yes

Note: "^" is a synonym for "**".

?- X is 3^7.
X = 2187

yes