Math Operations

Boris Yakimov

Operators of Operations

Just as in math, Please Excuse My Dear Aunt Sally describes the precedence applied to math in programming.


Parentheses

Exponents

Multiply

Divide (NOTE: Division will be complete in the order in which it appears in the problem, no ranking with division types.)

Add

Subtract

Basic Math Operators

+ (add),

- (subtract)

/ (divide)

* (multiply)

^ (Exponents)


Sample of Math with Various Operators

Addition +

intNumber = num1 + num2

Subtraction –

intNumber = num1 - 50

Multiplication *

intNumber = num1 * num2

Division /

intNumber = 51 / num2

Integer Division \

intNumber = 51 \ num2

Modulus Mod

intNumber = 5 mod 2

Exponents ^

intNumber = 5^3 ‘5 cubed


What is Regular Division?

Rounds the decimal portion if assigned to an integer.

This is the division with which you are most familiar

What is Integer Division?

Cuts off the decimal portion and returns the integer ( \ ):

19 \ 5 = 3


What is Modular Division?

Returns the remainder resulting form the division (mod):

19 Mod 5 = 4


FYI: there are three font colors as in White title, Blue headers, and Grey text.