﻿ Script Operators

# Script Operators

Top  Previous  Next

The operators available in FreeFlyer can be broken up into assignment operators, mathematical operators, logical operators, and String operators. For more information, be sure to see the Matrix, Array, and Variable Math and Flow Control pages.

## Assignment Operators

The assignment and increment operators can be used with Variables, Arrays, and Matrices. The examples in the table below use the following objects:

 Variable v1; Variable v2;

The following assignment and increment operators are available in FreeFlyer:

 Operator Description Examples Meaning = Assignment v1 = v2; v1 = v2; := Reference Assignment v1 := v2; Any usage of v1 will now refer to v2. ++ Increment v1++; v1 = v1 + 1; -- Decrement v1--; v1 = v1 - 1; += Addition Assignment v1 += v2; v1 = v1 + v2; -= Subtraction Assignment v1 -= v2; v1 = v1 - v2; *= Multiplication Assignment v1 *= v2; v1 = v1 * v2; /= Division Assignment v1 /= v2; v1 = v1 / v2; ^= Exponent Assignment v1 ^= v2; v1 = v1 ^ v2; %= Modulus Assignment v1 %= v2; v1 = v1 % v2;

Note: The reference assignment operator can be used to create a reference from one object to another. For example, you can configure an element of a List<Spacecraft> to refer to a separate Spacecraft object that you created in the object browser. You can also configure an element of a Struct to refer to an object that you created separately. The Object.ReferenceEquals() method can be used to check whether one object refers to another.

## Mathematical Operators

The examples in the table below use the following objects:

 Variable v1; Variable v2; Array a1; Array a2; Array a3; Matrix m1; Matrix m2; Matrix m3; Spacecraft Spacecraft1;

The following mathematical operators are available in FreeFlyer:

 Operator Description Examples + Addition v1 = Spacecraft1.A + v2; Element-by-scalar addition a1 = v1 + a2; m1 = v1 + m2; Element-by-element addition a1 = a2 + a3; m1 = m2 + m3; - Subtraction v1 = Spacecraft1.A – v2; Element-by-scalar subtraction a1 = v1 - a2; m1 = v1 - m2; Element-by-element subtraction a1 = a2 - a3; m1 = m2 - m3; * Multiplication v1 = Spacecraft1.A * v2; Element-by-scalar multiplication a1 = v1 * a2; m1 = v1 * m2; Matrix multiplication m1 = m2 * m3; Element-by-element multiplication a1 = a2 * a3; ** Element-by-element multiplication m1 = m2 ** m3; / Division v1 = Spacecraft1.A / v2; Element-by-scalar division a1 = v1 / a2; m1 = m2 / v1; Element-by-element division a1 = a2 / a3; Matrix division (equivalent to multiplying by the matrix inverse) m1 = m2 / m3; m1 = v1 / m2; \\ Element-by-element division m1 = m2 \\ m3; ^ Exponent v1 = Spacecraft1.A^v2; m1 = m2 ^ v1; Element-by-scalar exponent a1 = a2 ^ v1; Element-by-element exponent a1 = a2 ^ a3; m1 = m2 ^ m3; ^^ Element-by-scalar exponent m1 = m2 ^^ v1; % Modulus v1 = (Spacecraft1.W + Spacecraft1.TA)%360; Element-by-scalar modulus a1 = a2 % v1; m1 = m2 % v1; Element-by-element modulus a1 = a2 % a3; m1 = m2 % m3;

## The literal operators described below can be used to conveniently create literal Array or Matrix objects in FreeFlyer script. See the Matrix, Array, and Variable Math page for more information. The examples in the table below use the following objects:

 Array arr1; Matrix m1; Vector vec1; CoordinateSystem cs1; Spacecraft Spacecraft1;

FreeFlyer supports the following literal operators:

 Operator Description Examples { } Converts the specified argument to an Array arr1 = {vec1}; arr1 = {m1}; [ ] Converts the specified argument to a Matrix m1 = [arr1]; m1 = [vec1]; m1 = [cs1];

## The logical operators described below can be used in conjunction with the While and If statements. Nested Flow Control loops can be used to test and handle complex decisions. It is possible to test for multiple logical conditions in a single Flow Control statement by using the logical operators “and” or "or”. The examples in the table below use the following objects.

 Variable v1; Variable v2; Array a1; Array a2; Array a3; Matrix m1; Matrix m2; Matrix m3; Spacecraft Spacecraft1;

FreeFlyer supports the following logical operators.

 Operator Description Examples () Parentheses Used to group logical statements == Equal If (Spacecraft1.ElapsedTime == TIMESPAN(1 days));   Report Spacecraft1.ElapsedTime.ToDays(); End; Element-by-element comparison a1 = a2 == a3; m1 = m2 == m3; a1 = a2 == v1; m1 = m2 == v1; a1.IsEqualTo(a2); m1.IsEqualTo(m2); Object.ReferenceEquals() Checks whether the calling object refers to the argument object v1.ReferenceEquals(v2); < Less than If (Spacecraft1.ElapsedTime < TIMESPAN(1 days));   Step Spacecraft1; End; Element-by-element comparison a1 = a2 < a3; m1 = m2 < m3; a1 = a2 < v1; m1 = m2 < v1; > Greater than If (Spacecraft1.ElapsedTime > TIMESPAN(1 days));   Step Spacecraft1 to (Spacecraft1.AscendingNode); End; Element-by-element comparison a1 = a2 > a3; m1 = m2 > m3; a1 = a2 > v1; m1 = m2 > v1; <= Less than or equal to If (Spacecraft1.ElapsedTime <= TIMESPAN(1 days));   Step Spacecraft1; End; Element-by-element comparison a1 = a2 <= a3; m1 = m2 <= m3; a1 = a2 <= v1; m1 = m2 <= v1; >= Greater than or equal to If (Spacecraft1.ElapsedTime >= TIMESPAN(1 days));   Report Spacecraft1.Height; End; Element-by-element comparison a1 = a2 >= a3; m1 = m2 >= m3; a1 = a2 >= v1; m1 = m2 >= v1; and Logical AND If (Spacecraft1.ElapsedTime < TIMESPAN(5 days) and Spacecraft1.ElapsedTime > TIMESPAN(3 days));   Step Spacecraft1; End; Element-by-element Boolean AND a1 = a2 and a3; m1 = m2 and m3; a1 = a2 and v1; m1 = m2 and v1; != Logical NOT If (Spacecraft1.ElapsedTime != TIMESPAN(1 days));   Stop; End; Element-by-element comparison a1 = a2 != a3; m1 = m2 != m3; a1 = a2 != v1; m1 = m2 != v1; ! Boolean NOT If v1 is 0, this conditional statement evaluates to true, otherwise this conditional statement evaluates to false. If(!v1 == 1);    Stop; End; Element-by-element Boolean NOT v1 = !v2; a1 = !a2; m1 = !m2; or Logical OR If (Spacecraft1.ElapsedTime < TIMESPAN(5 days) or Spacecraft1.A > 6800);   Step Spacecraft1; End; Element-by-element Boolean OR a1 = a2 or a3; m1 = m2 or m3; a1 = a2 or v1; m1 = m2 or v1; IsType Is of the specified object type If (Spacecraft1.Propagator IsType RK89);     (Spacecraft1.Propagator AsType RK89).Tolerance = 1e-9; End;

### Compound Boolean Statements

Compound Boolean statements containing multiple operators are often used in If and While commands. Boolean expressions now follow standard order of operations. Consider the following script:

 Create Variable v = 0;   If(v == 0 or v == 0 and v == 1);   Watch v; End;

Previous to FreeFlyer 6.5, Boolean expressions evaluated left to right. In the script above, this leads to a grouping like:

(v == 0 or v == 0) and v == 1

In FreeFlyer 6.5 and higher, the and operator takes precedence over the or operator leading to a grouping like:

v == 0 or (v == 0 and v == 1)

In the example given, the expression evaluates to true in FreeFlyer 6.5, but false in previous versions. In FreeFlyer 6.5 and higher, you can also use parentheses to group expressions and explicitly specify the order of evaluation you desire.

## There are a number of String-specific operators that are unique in how they are evaluated. None of the boolean-returning operators below can be used in-line in conditional statements as they all return an Array of boolean values. The examples in the table use the following objects.

 Array ar1; String s1; StringArray sa1; StringArray sa2; StringArray sa3;

FreeFlyer supports the following String operators.

 Operator Description Examples + Concatenation sa2 = sa1 + s1 Element-by-element concatenation sa3 = sa1 + sa2 == Equals ar1 = sa1 == s1 Element-by-element equals ar1 = sa1 == sa2 != Not equals ar1 = sa1 != s1 Element-by-element not equals ar1 = sa1 != sa2