summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/00_syntax/26_exponentiation
blob: 1aab257793b98ca5792ab0e09af554e0f5d4de41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
The exponentiation and exponentiation assignment operands allow raising
the base operand value to the given power.


1. The `**` operator returns the result of raising the first operand to
the power of the second operand.

-- Expect stdout --
[
	1,
	4,
	9223372036854775808,
	-9223372036854775808,
	-0.25,
	2.75568
]
-- End --

-- Testcase --
{%
	printf("%.J\n", [
		2 ** 0,
		2 ** 2,
		2 ** 63,
		-2 ** 63,
		-2 ** -2,
		1.5 ** 2.5
	]);
%}
-- End --


2. The `**=` operator raises the lhs variable or field value to the
power value in the rhs expression.

-- Expect stdout --
[
	4,
	-0.25,
	2.75568
]
-- End --

-- Testcase --
{%
	x = 2;
	y = -2;
	z = 1.5;

	x **= 2;
	y **= -2;
	z **= 2.5;

	printf("%.J\n", [ x, y, z ]);
%}
-- End --