Math Operations

Note

Don’t worry about memorizing these. The important ones are listed at the top of this document. Just try to know the basic ones from math.

There are different kind of math operations in BCL.

Here is a list of all the math operations

Order of operations does apply. If you aren’t sure what the order will be when compiled, then you can put some expressions in parenthese, (10+10) * 2 for example.

  • Multiplication *

  • Division /

  • Subtraction -

  • Addition +

  • Exponentiation (raise to a power) **

  • Is equal to ==

  • Is not equal to !=

  • Is less than <

  • Is greater than >

  • Is less than or equal to <=

  • Is greater than or equal to >=

Logic Operators

These work on boolean (see section on data types). Although, nearly all types do have a “truthiness”. This just determines what a value should become if we want it to act like a boolean. For example, ints are truthy if not zero, otherwise they are falsey.

  • And and

  • Or or

  • Not not (prefix)

Stuff we learn about later

  • Indexing [index] (postfix)

  • Reference & (prefix)

  • Dereference * (prefix)

  • Namespace ::

Bitwise operation

These work on bits directly. These work like logic gates for each bit (except for left and right shift).

  • Xor ^

  • And &

  • Or |

  • Left Shift <<

  • Right Shift >>

  • Not ~ (prefix)

Order of Operations

This works like PEMDAS. If something appears first in this list, the compiler will do it first.

Operations

Operation(s)

example

associativity

Parenthese ()

(5+5)

N/A

Namespace ::

stdlib::println

left

Dereference *

*my_reference

left

Access Member .,
Index []
var.member,
var[index]
left,
left

Reference &

&x

left

Cast as

22 as i8

left

Exponentiation **

2**6

right

Bitwise Not ~

~(-255)

N/A

Modulo %,
Div /,
Mul *
10 % 2,
22 / 11,
2 * 15
left,
left,
left,
left
Sum +,
Sub -
8 + 9,
10 - 4
left,
left
Left Shift <<,
Right Shift >>
69<<2,
420>>2
left,
left
Bitwise And &,
Bitwise Xor ^
4&5,
4^5
left,
left

Bitwise Or |

4|5

left

Is Equal To ==,
Not Equal To !=,
Less Than or Equal To <=,
Greater Than or Equal To >=,
Less Than <,
Greater Than >
==,
!=,
<=,
>=,
<,
>
left,
left,
left,
left,
left,
left

Logic Not not

not true

N/A

Logic And and

true and false

Left

Logical Or or

true or false

left

Assignment Sum +=,
Assignment Sub -=,
Assignment Div /=,
Assignment Mul *=
x += 12;,
x -= 12;,
x /= 12;,
x *= 12;
N/A,
N/A,
N/A,
N/A