User Manual
MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
127
3.2 MCL Math
3.2.1 Math Functions
MCL includes a full complement of math and comparison functions. MCL supports 32 bit integer
math, both signed and unsigned. It also supports oating point math. A signed value denotes
whether the resulting value is positive or negative.
3.2.2 Number Bases
Although all calculations are handled internally in binary, users can refer to numbers as decimal,
hexadecimal or binary, whichever is most convenient for the programmer. For example, the
number 2349 can be referred to as:
2349 Decimal
0x092D Hexadecimal
%100100101101 Binary
Leading zeros are not required for hex or binary numbers, but may be used if desired. When
using signed integers (sbyte, sword, slong) it is probably a good idea to stick to decimal notation
to avoid confusion.
3.2.3 Math and Operators
Operators are what makes math work, by performing a function. An example of an operator
would be + (Addition), - (Subtraction), * (Multiplication) and / (Division). All these symbols
represent an operation to be performed. However, the operators need something to do, so we
add operands which are better known as arguments. Math arguments are the values used in an
expression.
In the following section you will see the word “expression” used many times. This refers to
something like 1+2. The expression 1+2 has one operator (+) and two arguments(1 and 2) or
operands.
3.2.4 Operators
Operator Description
- Changes the value of an expression from positive to negative. Also used in subtraction.
ABS Returns the absolute value of an expression.
SIN Returns the integer sine of an expression.
COS Returns the integer cosine of an expression.
SQR Returns the integer square root.
BIN2BCD Converts expression from binary to packed binary coded decimal format.
RANDOM Returns a random 32 bit number generated from a seed value.
- Subtraction. Also used to sign a value.
+ Addition.
* Multiplication, returns the low 32bits of a integer multiplication result.
/ Division.
** Returns high 32 bits of an integer multiplication result.
*/ Fractional integer multiplication.
// Remainder of Integer Division.