<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../style.css">
<title>
Gambas Documentation - Arithmetic Operators
</title>
</head>
<table class="none" width="100%" cellpadding="0" cellspacing="0" border="0">
<tr><td align="left">
<font size="-1">
<a href="../../help+en"><img class="flag" alt="Home" border="0" src="../../img/lang/en.png" align="center"></a>&nbsp;
<a href="../lang+en">Up</a>&nbsp;
<a href="append+en">Previous</a>&nbsp;
<a href="array+en">Next</a>&nbsp;
</td></tr></table>
<div class="notab">
<h1>
Arithmetic Operators
</h1>
<table class="table" border="0" bordercolor="#000000" cellpadding="4" cellspacing="0">
<tr class="dark"><td valign="top">
<u>Number</u> <tt><b>+</b></tt> <u>Number</u>
</td><td valign="top">
Adds two numbers.
</td></tr>
<tr><td valign="top">
<tt><b>-</b></tt> <u>Number</u>
</td><td valign="top">
Computes the opposite sign of a number. Zero is the opposite of itself.
</td></tr>
<tr class="dark"><td valign="top">
<u>Number</u> <tt><b>-</b></tt> <u>Number</u>
</td><td valign="top">
Subtracts two numbers.
</td></tr>
<tr><td valign="top">
<u>Number</u> <tt><b>*</b></tt> <u>Number</u>
</td><td valign="top">
Multiplies two numbers.
</td></tr>
<tr class="dark"><td valign="top">
<u>Number</u> <tt><b>/</b></tt> <u>Number</u>
</td><td valign="top">
Divides two numbers.  A <a href="../error/zero+en">Division By Zero (#26)</a> error will occur if the value of the number to the right of the slash is zero.
</td></tr>
<tr><td valign="top">
<u>Number</u> <tt><b>^</b></tt> <u>Power</u>
</td><td valign="top">
Raises <u>Number</u> to the power <u>Power</u>.
<p>
For example, <tt>4 ^ 3 = 64</tt>
</td></tr>
<tr class="dark"><td valign="top">
<u>Number</u> <tt><b>\</b></tt> <u>Number</u>
<p>
<u>Number</u>&nbsp;<tt><a href="div+en">DIV</a></tt>&nbsp;<u>Number</u>
</td><td valign="top">
Computes the quotient of the two <a href="type/integer+en">Integer</a> numbers, truncating the result.  A <a href="../error/zero+en">Division By Zero (#26)</a> error will occur if the value of the number to the right of the backslash is zero.
<p>
For example <tt>13 \ 7 = 2</tt>
<p>
<tt>A \ B = <a href="int+en">Int</a>(A / B)</tt>
</td></tr>
<tr><td valign="top">
<u>Number</u> <tt><a href="mod+en">MOD</a></tt> <u>Number</u>
</td><td valign="top">
Computes the remainder of the quotient of the two numbers.
A <a href="../error/zero+en">Division By Zero (#26)</a> error will occur if the value of the <a href="instr+en">InStr</a> to the right of the operator <tt><a href="mod+en">MOD</a></tt> is zero.
</td></tr>
</table>
<p>
<h2>Comparison</h2>
<p>
<table class="table" border="0" bordercolor="#000000" cellpadding="4" cellspacing="0">
<tr class="dark"><td valign="top">
<u>Number</u> <tt><b>=</b></tt> <u>Number</u>
</td><td valign="top">
Returns <a href="true+en">TRUE</a> if two numbers are equal.
</td></tr>
<tr><td valign="top">
<u>Number</u> <tt><b>&lt;></b></tt> <u>Number</u>
</td><td valign="top">
Returns <a href="true+en">TRUE</a> if two numbers are different.
</td></tr>
<tr class="dark"><td valign="top">
<u>Number1</u> <tt><b>&lt;</b></tt> <u>Number2</u>
</td><td valign="top">
Returns <a href="true+en">TRUE</a> if <u>Number1</u> is strictly lower than <u>Number2</u>.
</td></tr>
<tr><td valign="top">
<u>Number1</u> <tt><b>></b></tt> <u>Number2</u>
</td><td valign="top">
Returns <a href="true+en">TRUE</a> if <u>Number1</u> is strictly greater than <u>Number2</u>.
</td></tr>
<tr class="dark"><td valign="top">
<u>Number1</u> <tt><b>&lt;=</b></tt> <u>Number2</u>
</td><td valign="top">
Returns <a href="true+en">TRUE</a> if <u>Number1</u> is lower or equal than <u>Number2</u>.
</td></tr>
<tr><td valign="top">
<u>Number1</u> <tt><b>>=</b></tt> <u>Number2</u>
</td><td valign="top">
Returns <a href="true+en">TRUE</a> if <u>Number1</u> is greater or equal than <u>Number2</u>.
</td></tr>
</table>
<p>
If the result of a Comparison is assigned to an integer variable, then the result is either -1 (True) or 0 (False)
<p>

<p>
<h2>Order of evaluation</h2>
<table class="table" border="0" bordercolor="#000000" cellpadding="4" cellspacing="0">
<tr><th>
Operator
</th><th>
Example
</th></tr>
<tr class="dark"><td valign="top">
<tt>-</tt> (negation)
</td><td valign="top">
<tt>f =  - g ^ 2</tt> is the same as <tt>( - g ) ^ 2</tt>
</td></tr>
<tr><td valign="top">
<tt>^</tt>
</td><td valign="top">
<tt>i = 4 ^ 2 * 3 ^ 3</tt> is the same as <tt>(4 ^ 2) * ( 3 ^ 3 )</tt>
</td></tr>
<tr class="dark"><td valign="top">
<tt>* /</tt>
</td><td valign="top">
<tt>i = 4 * 2 + 3 * 3</tt> is the same as <tt>(4 * 2) + ( 3 * 3 )</tt>
</td></tr>
<tr><td valign="top">
<tt>+ -</tt>
</td><td valign="top">
<p>
</td></tr>
<tr class="dark"><td valign="top">
= &lt;&gt; &gt;= &lt;= &gt; &lt;=
</td><td valign="top">
<tt>i = 4 + 2 = 5 + 1</tt> is the same as <tt>( 4 + 2 ) = ( 5 + 1 )</tt>
</td></tr>
<tr><td valign="top">
<tt><a href="or+en">OR</a> <a href="and+en">AND</a> <a href="xor+en">XOR</a></tt>
</td><td valign="top">
<tt>i = a &gt; 10 <a href="and+en">AND</a> a &lt; 20</tt> is the same as <tt>( a &gt; 10 ) <a href="and+en">AND</a> ( a &lt; 20 )</tt>
</td></tr>
</table>
<p>
If in doubt, rather use braces ( ) to group subexpressions.
<p>
<hr><b>See also</b><br>
<a href="../cat/logicop+en">Logical Operators</a>&nbsp;

</div>
</body>
</html>

