[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.3.1.5 Arithmetic ($M)

The Arithmetic command allows simple arithmetic between Cogsys variables.

This command is used to perform simple integer arithmetic on two numbers (either variables or constants) and then store the result in a Cogsys variable. The operators allowed in the $M command are:

+
addition
-
subtraction
*
multiplication
/
division
\
modulus (remainder)

Note that Cogsys variables are stored as signed long integers; an operation with a result that exceeds 2,147,483,647 will yield an invalid negative number as a result, and similarly for underflow.

Also note that in the case of divide-by-zero (and modulus-zero), the value returned will be -1,073,741,825.

Name:
Arithmetic
Class:
Control
Code:
$M
Syntax:
$Mvdest=value1opvalue2
vdest is a variable reference
value1 and value2 are numbers
op is a character, must be one of `+', `-', `*', `/', `\'
System:
Cogsys performs the requested operation on the two numbers and stores the result in the variable vdest.

Test Files:
MATH_T01.IN: Tests basic operation, including an overflow example

 
@CPress any key to enter two integer values to
add, subtract, multiply, divide, and modulus (\$M)#R

Enter first integer number  (V10): $GV10
Enter second integer number (V11): $GV11

$MV12=V10+V11
$SV10 + $SV11 = $SV12

$MV12=V10-V11
$SV10 - $SV11 = $SV12

$MV12=V10*V11
$SV10 * $SV11 = $SV12

$MV12=V10/V11
$SV10 / $SV11 = $SV12

$MV12=V10\V11
$SV10 \\ $SV11 = $SV12

Overflow example:  $AV10=1 $AV11=0 $MV12=V10/V11

$SV10 / $SV11 = $SV12

Done.  Press any key to exit.#R

Examples:

input
$MV12=12*4
cogsys
Assigns 48 (12 * 4) to variable V12

input
$MV12=V12+1
cogsys
Increments the value of variable V12 by one



This document was generated on November, 24 2008 using texi2html