Operators, Assignment, Conversions, and Member Access

Arithmetic follows the conventions used in most languages. Available operators fall into four categories: binary operators, unary operators, equality operators, and the access operator.

The following binary operators are available, in order of precedence:

Table 1: FISH Binary Operators
Operator Description
^ Exponent
/ Division (always promotes to float)
// Floor Division floor(i/j)
* Multiply
% Modulus
- Subtract
+ Add
== Equals-Test
> Greater
< Lesser
# Not Equals
>= GreaterEq
<= LessEq
& And
| Or
Table 2: FISH Binary Operator Type Supported
Left Type Boolean Integer Real String Vector Pointer Index Tensor List Matrix Map Structure
Boolean ==<& ==<& ==&     ==& ==&          
Integer ==<& +-*/^//==<&% +-*/^//==<&%   * & +-*==<&   *      
Real ==& +-*/^//==<&% +-*/^//==<&%   * & ==<&   *      
String       +==<                
Vector   /*// /*//   +-/*//==       * +-/*//==    
Pointer           ==<            
Index & +-*==<& &     & +==<&          
Tensor   */ */   *     +-*== * +-*    
List ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
Matrix   */ */   +-*==     +-*== * +-*==    
Map                     ==  
Structure                       ==
  1. < indicates support for comparison operators in general (<, >, <=, and >=).
  2. == implies support for #.
  3. & implies support for |.
  4. Lists are special, in that ALL operators apply to lists, but their effects are applied to the elements of the list.
Table 3: List of FISH Unary Operators
Operator Description Types Supported
- Negation Integer, Real, Vector, List, Matrix, Tensor
~ Logical Not Boolean, Integer, Real, Pointer, Index
Table 4: List of FISH Assignment Operators
Operator Description Types Supported
= Assignment All types, and intrinsic on left.
+= Add and Assign As + binary operator.
-= Subtract and Assign As - binary operator.
/= Divide and Assign As / binary operator.
*= Multiply and Assign As * binary operator.

Binary operators are always applied in the order of precedence given. Arbitrary numbers of parenthesis may be used to make the order of evaluation explicit; expressions within parenthesis are evaluated before anything else, and inner parenthesis are evaluated first. As an example, FISH evaluates the variable xx as 133:

xx = 6/3*4^3+5

The expression is equivalent to:

xx = ( (6/3) * (4^3) ) + 5

If there is any doubt about the order in which arithmetic operators are applied, then parentheses should be used for clarification.

If either of the two arguments in an arithmetic operation is of floating-point type, then the result will be floating-point. If both of the arguments are integers, then the result will be integer, except for the division operator which will always promote to float. Tensors are automatically promoted to matrices using the same rules.

The division operator will always promote to float.

The floor division operator is define as floor(i/j) - this means that -1//3 will return -1.

Member Access Operator

The last operator available is the member access operator (->). This operator is available to access components of vector, tensor, and structure types.

The structure type allows the user to define their own access symbols, as the names of the structure members.

The member access operator can be used on the left or right hand side of an assignment, as is a convenient way to access the individual components of a vector or a tensor. It may be used directly on a symbol or local value, or as part of an extended expression.

local a = vector(1,2,3)
local b = a->x
a->y = 4
gp.pos(pnt)->x = 3.0
local c = zone.strain.rate(pnt)->zz
Table 5: List of member access operators
Type Access
Vector x, y, z
Tensor xx, xy, xz, yy, yz, zz
Structure defined by user

.