Operators

Top  Previous  Next

Unary operators

-

Negation

not

Logical or bitwise NOT

@

Explicit function pointer reference

Expression operators

+

Addition & string concatenation

-

Subtraction

*

Multiplication

/

Division (floating-point)

div

Euclidean division

mod

Remainder of Euclidean division

sar

Bitwise shift arithmetic right

shr

Bitwise shift right

shl

Bitwise shift left

in

Present in an array, set, or substring in a string

not in

Absence in an array, set, or substring in a string

and

Boolean or bitwise AND

or

Boolean or bitwise OR

xor

Boolean or bitwise XOR

implies

Logical IMPLIES

is

Class, interface type test

as

Class, interfaces safe cast

implements

Tests if a class implements an interface

=

Equality test

<>

Difference test

<

Lesser test

<=

Lesser or equal test

>

Greater test

>=

Greater or equal test

Ternary operators

if .. then ..

Conditional value or default value

if .. then .. else ..

Conditional value with alternative

Assignment operators

:=

Assignment

+=

Addition & concatenation compound operator

-=

Subtraction compound operator

*=

Multiplication compound operator

/=

Division compound operator

 

Available operators:

Since pointers don't exist in the language, the ^ and ^= operators are available for overloading.

 

<<

>>

^

 

 

mytoggle_plus1See example using basic arithmetic operators

var a := StrToIntDef(w3_Prompt('Enter 1st number','0'),0);

var b := StrToIntDef(w3_Prompt('Enter 2nd number','0'),0);

 

 

WriteLn(Format('%d + %d = %d', [a, b, a + b]));

WriteLn(Format('%d - %d = %d', [a, b, a - b]));

WriteLn(Format('%d * %d = %d', [a, b, a * b]));

WriteLn(Format('%d / %d = %d', [a, b, a div b]));

WriteLn(Format('%d mod %d = %d', [a, b, a mod b]));

WriteLn(Format('%d ^ %d = %d', [a, b, Trunc(Power(a, b))]));

{

X=0  

Y=0

0 + 0 = 0

0 - 0 = 0

0 * 0 = 0

0 / 0 = NaN

0 mod 0 = NaN

0 ^ 0 = 1 

 

X=0  

Y=1

0 + 1 = 1

0 - 1 = -1

0 * 1 = 0

0 / 1 = 0

0 mod 1 = 0

0 ^ 1 = 0 

 

X=19  

Y=4

19 + 4 = 23

19 - 4 = 15

19 * 4 = 76

19 / 4 = 4

19 mod 4 = 3

19 ^ 4 = 130321 

}

 

 

To see more examples, click here.