Category:Arithmetic Operations: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
(edit)
No edit summary
 
Line 1: Line 1:
{{:Arithmetic Operations}}
The four arithmetical operations supported by BR are addition, subtraction, multiplication and division. These operations literally correspond with their respective mathematical operators. Each of these operators may be followed by an equal sign, in which case the result of the operation is assigned to the variable on the left side of the operator:
 
{|
|-valign="top"
|width="10%"|'''Operator'''|| '''Effect'''
|-valign="top"
|width="10%"|'''+'''||addition
|-valign="top"
|width="10%"|'''+='''||addition of the left operand to the right operand followed by assignment of the result to the left operand
|-valign="top"
|width="10%"|'''-'''||subtraction
|-valign="top"
|width="10%"|'''-='''||subtraction of the right operand from the left operand followed by assignment of the result to the left operand
|-valign="top"
|width="10%"|'''*'''||multiplication
|-valign="top"
|width="10%"|'''*='''||multiplication of the left operand by the right operand followed by assignment of the result to the left operand
|-valign="top"
|width="10%"|'''/'''||division
|-valign="top"
|width="10%"|'''/='''||division of the left operand by the right operand followed by assignment of the result to the left operand
|-valign="top"
|width="10%"|'''**'''||power
|}
 
Below are some examples of these operators:
 
00010 let a = 2
00020 let a += 3    ! this is equivalent to '''let a = a + 3''', and the resulting value of a is 5
00030 let a *= 4    ! this is equivalent to '''let a = a * 4''', and the resulting value of a is 20
00040 let a /= 10    ! this is equivalent to '''let a = a / 10''', and the resulting value of a is 2
00050 let a = 2 ** 5 ! raises 2 to the 5th power, resulting in 32
 
All of these mathematical operators are examples of [[Binary operations|binary operations]].
 
Now consider two more operators that use the same signs as addition and subtraction, yet each perform a different function.
 
The first one is [[Unary operations|unary plus]] '''+'''. The result of the unary plus operator is the value of its operand. The operand to the unary plus operator must be a numeric variable.
 
For example,
 
00010 let b = - 1
00020 let a = + b
 
The second one is [[Unary operations|unary minus]] '''-'''. The result of the unary minus operator is the opposite value of its operand. The operand to the unary minus operator must be a numeric variable.
 
For example,
 
00010 let b = - 1
00020 let a = - b
 
As a result, the value of a becomes 1, which is the opposite of -1.


<noinclude>
<noinclude>
[[Category:Operations]]
[[Category:Operations]]
</noinclude>
</noinclude>

Latest revision as of 13:49, 13 May 2014

The four arithmetical operations supported by BR are addition, subtraction, multiplication and division. These operations literally correspond with their respective mathematical operators. Each of these operators may be followed by an equal sign, in which case the result of the operation is assigned to the variable on the left side of the operator:

Operator Effect
+ addition
+= addition of the left operand to the right operand followed by assignment of the result to the left operand
- subtraction
-= subtraction of the right operand from the left operand followed by assignment of the result to the left operand
* multiplication
*= multiplication of the left operand by the right operand followed by assignment of the result to the left operand
/ division
/= division of the left operand by the right operand followed by assignment of the result to the left operand
** power

Below are some examples of these operators:

00010 let a = 2
00020 let a += 3     ! this is equivalent to let a = a + 3, and the resulting value of a is 5
00030 let a *= 4     ! this is equivalent to let a = a * 4, and the resulting value of a is 20
00040 let a /= 10    ! this is equivalent to let a = a / 10, and the resulting value of a is 2
00050 let a = 2 ** 5 ! raises 2 to the 5th power, resulting in 32

All of these mathematical operators are examples of binary operations.

Now consider two more operators that use the same signs as addition and subtraction, yet each perform a different function.

The first one is unary plus +. The result of the unary plus operator is the value of its operand. The operand to the unary plus operator must be a numeric variable.

For example,

00010 let b = - 1
00020 let a = + b

The second one is unary minus -. The result of the unary minus operator is the opposite value of its operand. The operand to the unary minus operator must be a numeric variable.

For example,

00010 let b = - 1
00020 let a = - b

As a result, the value of a becomes 1, which is the opposite of -1.

This category currently contains no pages or media.