Operators in FISH
Arithmetic performed with operators follows the conventions used in most languages. The five kinds of operators found in FISH are the following.
Binary Math Operators
The following binary operators are listed in order of precedence.
Operator 
Description 

^ 
Exponent 
/ 
Division (always promotes to float) 
// 
Floor Division floor(i/j) 
* 
Multiply 
% 
Modulus 
 
Subtract 
+ 
Add 
== 
EqualsTest 
> 
Greater 
< 
Lesser 
# 
Not Equals 
>= 
GreaterEq 
<= 
LessEq 
& (and) 
And 
 (or) 
Or 
Note that the keywords and
, or
, and not
can be used as well as the single character operators &, , and ~ respectively.
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 
== 
< indicates support for comparison operators in general (<, >, <=, and >=).
== implies support for #.
& implies support for .
Lists are special, in that ALL operators apply to lists, but their effects are applied to the elements of the list.
Notes on Binary Operators
Binary operators are always applied in the order of precedence given (see table above). 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 floatingpoint type, then the result will be floatingpoint. 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.
Unary Math Operators
Operator 
Description 
Types Supported 

 
Negation 
Integer, Real, Vector, List, Matrix, Tensor 
~ (not) 
Logical Not 
Boolean, Integer, Real, Pointer, Index 
Assignment Operators
Operator 
Description 
Types Supported 

= 
Assignment 
All types, and intrinsic on left 
+= 
Add and Assign 
Same as + binary operator 
= 
Subtract and Assign 
Same as  binary operator 
/= 
Divide and Assign 
Same as / binary operator 
*= 
Multiply and Assign 
Same as * binary operator 
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
Type 
Access 

Vector 

Tensor 

Structure 
defined by user 
Splitting Operators
The splitting logic is invoked when ::
is applied to an argument of a function that will support splitting. The reference document for a function supporting splitting will use the notation :=
for its read and/or write operations (see zone.maxid
or data.vector.value
, for instance).
In addition, the assignment operators shown above may be used with splitting, but require appending ::
to the operator to signal use in a splitting context.
See the topic Splitting: Using Multiple Threads in FISH for a complete discussion.
Operator 
Description 
Types Supported 

:: 
Split Argument 
Iterative types as function arguments 
=:: 
Assignment 
All types, and intrinsic on left 
+=:: 
Add and Assign 
Same as + binary operator 
=:: 
Subtract and Assign 
Same as  binary operator 
/=:: 
Divide and Assign 
Same as / binary operator 
*=:: 
Multiply and Assign 
Same as * binary operator 
⇐ Functions: Structure, Evaluation and Calling Scheme  Executing FISH: Inline FISH or FISH Fragments ⇒
Was this helpful? ...  Itasca Software © 2024, Itasca  Updated: Sep 26, 2024 