11.2 Arithmetic Operators

11.2.1 Sum (+)

The sum operator applied to numeric operands performs the standard arithmetic sum, while applied to string operands returns their concatenation:

5 + 3

8

"foo" + "bar"

foobar

When applied to a numeric and a string operand, the number is converted into a string:

"foo" + 10

foo10

11.2.2 Subtraction (-)

The subtraction operator can only be applied to numeric operands; it returns the standard arithmetic subtraction:

26 - 8

18

10 - 20

-10

11.2.3 Unary Minus (-)

Unary minus can only be applied to a single numeric operand it returns the same operand with opposite sign.

Assuming variable x stores the value 5 and variable y stores the value -5:

- x

-5

- y

5

11.2.4 Multiplication (*)

The multiplication operator, applied to numeric operands, performs the standard arithmetic multiplication:

5 * 3

15

-2 * 4

-8

A string multiplied by a number n returns the string repeated n times:

"#" * 10

##########

11.2.5 Division (/)

The division operator can only be applied to numeric operands; it returns the standard arithmetic division. Since Cows can only handle integers, results will be truncated.

4/2

2

5/2

2

11.2.6 Modulus (%)

The modulus operator can only be applied to numeric operands; it returns the rest of the division of the first operand by the second.

4/2

0

5/2

1

8/3

2

11.2.7 Power (**)

The power operator can only be applied to numeric operands; it returns the first operand raised to the second:

10 ** 3

1000

This manual can be downloaded from http://www.g-cows.org/.