Back
| Next
Lesson
Manipulating Numbers
We've discussed the benefits of using variables in lesson
#004, lower maintenance and flexibility. Today we're going to expand on
the flexibility aspect of using variables.
There are 3 basic types of data; numbers,
text, and points.
The next 3 lessons will discuss each one of these individually. Numbers
include both real and integer data types.
Operators
The basic operators include multiplication
(*), division
(/), addition
(+), and subtraction
(-). A higher level of operators
include exponential notation
(** or ^) and scientific
notation (e).
005
i = 6+2 /* i=008
006 i = 6-2 /* i=004
007 i = 6*2 /* i=012
008 i = 6/2 /* i=003
009 i = 6**2 /* i=036
010 i = 6^2 /* i=036
011 i = 6e2 /* i=600
Evaluation Order
ARRIS follows the typical evaluation priorities:
- 1st) Exponential or Scientific Notations
- 2nd) Multiplication or Division Operators
- 3rd) Addition or Subtraction Operators
012 i = 6^2+3*4
If you did not have priority rules, you could evaluate line #012 as (((6^2)+3)*4)=156 or (6^(2+(3*4)))=78364164096 or ((6^2)+(3*4))=048, the latter is true with the above evaluation order when parenthesis are not applied.
013 i = 6+2-3+4
The same is true with line #013, (((6+2)-3)+4)=009 or ((6+2)-(3+4))=020, the former is true when parenthesis are not applied. Why? Because if different operators have the same priority level, they are evaluated from left to right. As you can see in the above examples, parenthesis have the highest priority level and can change the evaluation order.
Parenthesis can be nested. The inner-most set of parenthesis are evaluated first, working its way to the outer-most set of parenthesis. When 2 or more sets of parenthesis fall on the same level, they are evaluated from left to right.
Tip: Not only should parenthesis be used to dictate the evaluation order, they should also be used to increase the readability of your equation.
Shortcut Operators
Sigmac offers a couple of shortcuts to increment or decrement a variable by one.
014 ivar++ /* same as ivar=(ivar+1)
015 ivar-- /* same as ivar=(ivar-1)
Dot Operators
Dot operators perform specialize functions (note data types required and returned):
integer = integer1 .mod. integer2
Returns an integer of the remainder after integer2 is divided into integer1.
016 i = 12.mod.2 /* i=2
017 ieven = ieven+(ieven.mod.2) /* Will always round i2 to the next higher even number
real = real1 .rnd. real2
Rounds a real1 to the nearest multiple of real2. Rounding differences greater than or equal to 0.50% of r2 will round up.
018 r = 12.50.rnd.3.0 /* r=12.0
019 r = 13.50.rnd.3.0 /* r=15.0
real = real1 .min. real2 & real = real1 .max. real2
Returns the smaller or larger of the 2 numbers (real1 & real2).
020 r = 12.50.min.3.0 /* r=03.0
021 r = 12.50.max.3.0 /* r=12.5
$utilities
There are numerous $utilities that deal with algebra and trigonometry. I'll just quickly list them here, leaving the exploration to you and a much later lesson.
Algebra Returns:
$abs(r1) Absolute value of r1
$frac(r1) Fractional portion of r1
$int(r1) Whole number portion of r1 (always rounds down)
$sign(r1) Either -1 or +1, depending on whether r1 is negative or positive
$sqrt(r1) Square root of r1
Trigonometry Returns:
$sin(r1) Sine of angle r1
$asin(r1) Arcsine of r1
$sinh(r1) Hyperbolic sine of r1
$cos(r1) Cosine of angle r1
$acos(r1) Arcosine of r1
$cosh(r1) Hyperbolic cosine of r1
$tan(r1) Tangent of angle r1
$atan(r1) Arctangent of r1
$tanh(r1) Hyperbolic tangent of r1
That's all for now,
Steve
This lesson was brought to you by SCG consulting. All written materials related to these Sigmac lessons are copyrighted by SCG and intended for personal use only. Any commercial or non-commercial reproduction for public use is prohibited without written consent from SCG.
Back
| Next
Lesson