Operators

Home • Gallery • Tutorials • Download • Purchase • Site Map
 

Arithmetic Operators

Fractal Science Kit programs support the following arithmetic operators:

+ Addition
- Subtraction
* Multiplication
/ Division
^ Exponentiation
% Modulus
- Unary Minus

All of the arithmetic operators, with the exception of the modulus operator, operate on complex operands and return a complex result. The modulus operator operates on real operands and returns a real result. The modulus operator divides its 1st operand by its 2nd operand, and returns the remainder as its result.

Comparison Operators

Fractal Science Kit programs support the following comparison operators:

=  Equal To
<> Not Equal To
<= Less Than or Equal To
<  Less Than
>= Greater Than or Equal To
>  Greater Than

The operators = and <>, operate on complex operands and return a Boolean result. The remaining operators (<=, <, >=, >), operate on real operands and return a Boolean result.

Logical Operators

Fractal Science Kit programs support the following logical operators:

|| Logical OR
&& Logical AND
~  Logical NOT (unary operator)

These logical operators operate on Boolean operands and return a Boolean result.

Operator Precedence

Operator precedence is used to determine how to evaluate expressions involving multiple operations where parentheses are not present to guide the compiler. Operators with the highest precedence are evaluated first, followed by operators of the next highest precedence, and so on, until the expression is resolved. Of course, parentheses can be used to dictate order, and are recommended if the clarity of the expression is improved.

The following table lists the operators in highest to lowest precedence:

^
- (Unary Minus)
*, /, %
+, -
=, <>, <=, <, >=, >
~
&&
||

Operators on the same row have the same precedence. When several operators of the same precedence are combined in an expression, they are evaluated left to right.

The operators ~, ||, &&, <=, <, >=, >, and %, operate only on the real component of the operands and the result of evaluating one of these operators produces a real result (i.e., the imaginary component is 0). The operators = and <> operate on complex operands but return a real result (i.e., the imaginary component is 0).

Example:

z = a*b*c              ' z = (a*b)*c
z = a*b + c/d          ' z = (a*b) + (c/d)
z = -a + b * -c        ' z = (-a) + (b * (-c))
z = a^b^c              ' z = (a^b)^c
t = a+b < c+d          ' t = (a+b) < (c+d)
t = a && b || c && d   ' t = (a && b) || (c && d)
t = ~a && b            ' t = (~a) && b
t = ~a = b             ' t = ~(a = b)

In the above example, the trailing comments provide functionally equivalent statements to those to the left of the comments.

 

Copyright © 2004-2019 Ross Hilbert
All rights reserved