# 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:

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 |

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.

Operator | Description | Types Supported |
---|---|---|

- | Negation | Integer, Real, Vector, List, Matrix, Tensor |

~ | Logical Not | Boolean, Integer, Real, Pointer, Index |

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

Type | Access |
---|---|

Vector | `x` , `y` , `z` |

Tensor | `xx` , `xy` , `xz` , `yy` , `yz` , `zz` |

Structure | defined by user |

.

⇐ Functions: Structure, Evaluation and Calling Scheme | Executing FISH: Inline FISH or FISH Fragments ⇒

Was this helpful? ... | PFC © 2021, Itasca | Updated: Feb 25, 2024 |