ooPIC Logo

ooPIC Programmer's Guide

 Chapter 11 - ooPIC Mathematics

Back to top of page ooPIC Mathematics
 Any mathematical formula that needs to be solved while an application's program is running requires that it be written out as an Expression in the program's code. ooPIC math is integer only, there is no support for floating point math.
Back to top of page Expressions
 An Expression is a written mathematical formula that details the values, operations and functions as well as the order in which the operations and functions are performed for the formula to be solved. The resulting value of the mathematical formula is the final value derived after all of the formula's operations and functions have been executed.

An Expression can be a single value or variable, or it can be comprised of several values and variables separated by Operators and functions.

Expressions can be used in the following situations:

  • An assignment statement that assigns the resulting value to a Variable
  • A flow control statement that conditionally changes the flow of the program depending on the resulting value.

If an Expression is comprised of more than one value or variable, then it is evaluated from left to right, performing in the order of precedence the operators and functions that it encounters.

Back to top of page Operators
 Operators are used to specify that a mathematical operation needs to be performed between two values. They are always performed by applying the value on the right side to the value on the left side in the manner specified by the operator.

The following is a list of Operators.

In the following example, the variable "A" is assigned the value of the Variable "B" plus the value of the variable "C" minus the value of the variable "D"

A = B + C - D

Back to top of page Precedence of Operators
 

The precedence of operators determines the order in which mathematical operations are executed. ooPIC languages follow the operator precedence rules of algebraic expressions. These rules dictate that the expression is scanned from left to right and that no operation is performed until it encounters an operator of lower or equal precedence.

NOTE: ooPIC order of precedence is NOT the same as in other programming languages, read the following carefully.

The following list defines ooPIC's order of precedence:

  1. Operators in parenthesis
  2. Negation (-)
  3. Multiplication (*), Division (/) and Modulus (Mod)
  4. Addition (+) and Subtraction (-)
  5. Relational expressions (=, <>, <, >, <=. >=)
  6. Logical AND (And)
  7. Logical OR (Or)
  8. Logical XOR (XOR)

Parenthesized expressions have the highest precedence, so their use is a good way for you to reduce ambiguity and make your programs more readable.

In the following example, the variable "A" is assigned the value of the Variable "C" divided by the value of the variable "D" plus the value of the variable "B"

A = B + C / D

In the following example, the variable "A" is assigned the value of the Variable "B" plus the value of the variable "C" divided by the value of the variable "D"

A = (B + C) / D

Back to top of page Arithmetic Operators
 The Arithmetic Operators perform basic arithmetic functions between two values.
Basic SyntaxC/Java SyntaxResulting value
{expr1} + {expr2}{expr1} + {expr2}The sum of the two expressions.
{expr1} - {expr2}{expr1} - {expr2}The difference of the two expressions.
{expr1} * {expr2}{expr1} * {expr2}The product of the two expressions.
{expr1} / {expr2}{expr1} / {expr2}The quotient of the two expressions.
{expr1} Mod {expr2}{expr1} % {expr2}The remainder of the two expressions.
Back to top of page Logical Operators
 

The Logical Operators perform the bitwise logic functions between two values

NOTE: C and Java syntax is nonstandard for logical operations.

Basic SyntaxC/Java SyntaxResulting value
{expr1} And {expr2}{expr1} & {expr2}The result of Logically ANDing the bits of the two expressions.
{expr1} Or {expr2}{expr1} | {expr2}The result of Logically ORing the bits of the two expressions.
{expr1} Xor {expr2}{expr1} ^ {expr2}The result of Logically Exclusively ORing the bits of the two expressions.
Not {expr1}~{expr1}The result of Logically Inverting the bits of {expr1}
Back to top of page Relational Operators
 The Relational Operators perform comparisons between two values.
Basic SyntaxC/Java SyntaxResulting value
{expr1} = {expr2}{expr1} == {expr2}1 if the two expressions are equal, 0 if not.
{expr1} <> {expr2}{expr1} != {expr2}1 if the two expressions are not equal, 0 if equal.
{expr1} < {expr2}{expr1} < {expr2}1 if {expr1} is less than {expr2}, 0 if not.
{expr1} > {expr2}{expr1} > {expr2}1 if {expr1} is more than {expr2}, 0 if not.
{expr1} <= {expr2}{expr1} <= {expr2}1 if {expr1} is less than or equal to {expr2}, 0 if not.
{expr1} >= {expr2}{expr1} >= {expr2}1 if {expr1} is more than or equal to {expr2}, 0 if not.
Back to top of page Functions
 Functions are used when one value needs to be converted from one form to another. They are performed by applying the value within the functions in parenthesis to the conversion process specified by the function. The result is in reference to binary radians. See the specific references for the trigonometric functions.

The following is a list of Function.

SyntaxResulting Value
Sin({expr})The binary formatted trigonometric sine of {expr}
Cos({expr})The binary formatted trigonometric cosine of {expr}

ooPIC Compiler Ver 6.0 (c) Copyright 1997 - 2007 Savage Innovations, LLC.