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.

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)

And

| (or)

Or

Note that the keywords and, or, and not can be used as well as the single character operators &, |, and ~ respectively.

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.

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 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.

Unary Math Operators

Table 3: List of FISH Unary Operators

Operator

Description

Types Supported

-

Negation

Integer, Real, Vector, List, Matrix, Tensor

~ (not)

Logical Not

Boolean, Integer, Real, Pointer, Index

Assignment Operators

Table 4: List of FISH 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
Table 5: List of member access operators

Type

Access

Vector

x, y, z

Tensor

xx, xy, xz, yy, yz, zz

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.

Table 6: List of Splitting Operators

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