Mathematical Operators

Slick-CŪ uses the operator precedence of C. The table below contains the unary operators that an expression can use.

Operator

Description

! e1

Logical NOT. Result is 1 if e1 evaluates to 0. Otherwise the result is 0.

~ e1

Bitwise complement.

- e1

Negation.

+ e1

No change.

++ v1

Increments the variable v1 and returns the result.

v1 ++

Returns the value of v1 and then increments the variable v1.

-- v1

Decrements the variable v1 and returns the result.

v1 --

Returns the value of v1 and then decrements the variable v1.

The binary and ternary operators for the Slick-C language are listed in the table below. In addition to the operators listed in the previous table, string concatenation is implied. If a binary operator does not exist between two unary expressions, concatenation is automatically performed.

All numeric operators, except bitwise operators, support floating point numbers. Bitwise operators support 32-bit integers for all platforms.

Operator

Description

=

Assign right operand to left operand.

:=

Declare new variable with type matching right operand and assign it the value of the right operand.

+=

Add left operand to right operand and assign to left operand.

-=

Subtract right operand from left operand and assign to left operand.

/=

Divide left operand by right operand and assign to left operand.

*=

Multiply left operand with right operand and assign to left operand.

|=

Bitwise OR left operand with right operand and assign to left operand.

^=

Bitwise XOR left operand with right operand and assign to left operand.

&=

Bitwise AND left operand with right operand and assign to left operand.

e1 ? e2 : e3

If expression e1 is TRUE (not the string 0), expression e2 is returned. Otherwise, expression e3 is returned.

&&

Logical AND. If left hand expression is false, right-hand expression is not evaluated.

||

Logical OR. If left hand expression is true, right-hand expression is not evaluated.

|

Bitwise OR.

^

Bitwise XOR.

&

Bitwise AND.

==

Equal. Performs a numeric or string comparison depending on the operands. This function is NOT identical to the C strcmp function (see :== operator below). If both operands are numbers, a numeric comparison is performed. Otherwise a string comparison is performed. In any case, leading and trailing spaces and tabs are stripped before the comparison is performed.

>

Greater than. Performs a numeric or string comparison depending on the operands. See == operator.

>=

Greater than or equal. Performs a numeric or string comparison depending on the operands. See == operator.

<

Less than. Performs a numeric or string comparison depending on the operands. See == operator.

<=

Less than or equal. Performs a numeric or string comparison depending on the operands. See == operator.

!=

Not equal. Performs a numeric or string comparison depending on the operands. See == operator.

:==

Exactly equal. Always performs string comparison. This is equivalent to the C expression: (strcmp(a,b)==0)

:!=

Not exactly equal. Always performs string comparison.

:<=

Exactly less than or equal. Always performs string comparison.

:<

Exactly less than. Always performs string comparison.

:>=

Exactly greater than or equal. Always performs string comparison.

:>

Exactly greater than. Always performs string comparison.

instanceof

Can be used to test if a class instance derives from a specific class or interface. It can be used in two ways: x instanceof MYCLASS, or x instanceof "MYCLASS". "MYCLASS" does not need to be a constant string, and x may be a typeless container variable. Slick-C's instanceof is slightly more powerful than Java's, since the right operand can be a string value rather than just a class name. Otherwise, it is essentially the same concept.

:+

Concatenation.

:+=

Append right operand (string) to the end of the left operand (string) and assign to the left operand. This is similar to the built-in strappend() function, but more convenient to use.

<<

Bitwise shift left.

>>

Bitwise shift right.

+

Addition.

-

Subtraction.

/

Division with possible floating point result.

intdiv

Division with integer result.

*

Multiplication.

%

Modulo (integer remainder).

Two sets of comparison operators exist. The operators <, >, =, !=, <=, and >= perform a numeric comparison if both string expressions are valid numbers. The operators :<, :>, :==, :!=, :<=, and :>= always perform a string comparison.

Select the appropriate comparison operator for performing a string or numeric comparison. Expressions may extend across line boundaries if the line ends in a binary operator or if the line ends with a backslash.

The table below shows examples of math operators in Slick-C.

Example

Operator

(1.0==1)

== true

(1e2==100)

== true

(1e2:==100)

== false

(" abc "=="abc")

== true

(" abc ":=="abc")

== false

(" abc ":!="abc")

== true

(" 1 "==1)

== true

(" 1 ":==1)

== false

("abc":<"def")

== true

1 2

:=="12"

1 ( 2)

:=="12"

pow(4,2)

==16

5%2

==1

5/2

==2

5/2.0

==2.5

5 intdiv 2.0

==2

5&2

==0

5|2

==7

(10<7)

== false

(10:<7)

== true