Subsections


Arithmetic Expressions

Arithmetic expressions gather the expressions used for any arithmetic computation: addition, multiplication, substraction, division, modulo, shift left and right, bitwise or, bitwise exclusive, bitwise and, bitwise complement. This Section introduced these operators with a special focus on the additive operator which is a multi-purpose operator.


Additive Expression

The additive operator (i.e. +) is used for arithmetic addition of integers, floating point numbers and characters, and is also used for string concatenation, list or array concatenation and set or bag union. Its functionality depends on the type of its operands: it is a polymorphic operator. Note that the choice of its functionality is done at evaluation time, not at compile time. That means that the functionality of an expression such as x + y is unknown until the evaluation time. Depending on the dynamic type of the operands x and y, it can be a simple arithmetic addition, a string or list or array concatenation, a set or bag union or it can raise an error.
When used as a arithmetic operator and when the two operands have not the same type, one of the operands can be automatically promote to the type of the second one. The promotion mechanism is the same as in the C or C++ languages: integer may be promoted to float, char may be promoted to float or integer.
General Information
Operator +
Type binary
Syntax expr + expr
Commutative yes
Operand Types integer, float, char, string, list, bag, set, array
Result Type see following table
Function multi functions according to operands: arithmetic addition, string concatenation, list or array concatenation, set or bag union.

Possible Operand Combinations
first operand type second operand type result type  
integer integer integer  
integer float float  
char char integer  
char integer integer  
char float float  
float float float  
string string string string concatenation
list list list list concatenation
array array array array concatenation
set set set set union
bag bag bag bag union

Expression Examples
expression result
1 + 2 3
1 + 2. 3.
2 + 2.3 4.3
'a' + 'b' 195
'a' + 1.2 98.200
"hello" + "world" "helloworld"
list(1, 2, 3) + list(2, 3, 4) list(1, 2, 3, 2, 3, 4)
set(1, 2, 3) + set(2, 3, 4) set(1, 2, 3, 4)
1 + "hello" raises an error
set(1, 2, 3) + list(2, 3, 4) raises an error


Multiplicative, Division and Minus Expressions

Multiplicative, division and minus expression syntax, semantics, associativity and precedence are quite identical to the corresponding C and C++ expressions. When operands have different types, promotionnal mechanisms are the same as for the additive operator.
General Information
Operators -
  *
  /
Type binary
Syntaxes expr - expr
  expr * expr
  expr / expr
Commutative - : no
  * : yes
  / : no
Operand Types integer, float, char
Result Type see following table
Functions - : substract
  * : multiply
  / : divide

Possible Operand Combinations
first operand type second operand type result type
integer integer integer
integer float float
integer char integer
char char integer
char integer integer
char float float
float float float
float integer float
float char float

Expression Examples
expression result
1 - 2 -1
3 * 2. 6.
2 * 'a' 194
'a' * 'b' 9506
1 / 2 0
1 / 2. .5000
1. / 2 .5000
1. / 2 .5000
"hello" * "world" raises an error
1 - "hello" raises an error


Shift, Mod, And, Or, XOr Expressions

Shift, modulo, and, or and xor expression syntax, semantics, associativity and precedence are quite identical to the corresponding C and C++ expressions. Operand types must be integer or char and the only possible type promotion is from char to integer.
General Information
Operators «
  »
  %
  &
  |
  ^
Type binary
Syntaxes expr « expr
  expr » expr
  expr % expr
  expr & expr
  expr | expr
  expr ^ expr
Commutative « : no
  » : no
  % : no
  & : yes
  | : yes
  ^ : yes
Operand Types integer, char
Result Type integer
Functions « : left shift
  » : right shift
  % : modulo
  & : bitwise and
  | : bitwise or
  ^ : bitwise exclusive or

Expression Examples
expression result
1 « 4 16
100 » 2 25
100 % 13 9
0xf12 & 0xf 2
0xf12 | 0xf 3871
0xf12 ^ 0xf 3869
'b' % '9' 8
2 « 1.2 raises an error
2 % 3.4 raises an error
2.1 % 3 raises an error


Sign Expressions

Sign expressions are the expressions using the unary operators + or -. The expression syntax, semantics, associativity and precedence are quite identical to the corresponding C and C++ expressions. These unary operators accept only integer, char and float operands.
General Information
Operators +
  -
Type unary
Syntaxes + expr
  - expr
Operand Types integer, char, float
Result Type see following table
Functions sign operator

Possible Operand Combinations
operand type result type
integer integer
float float
char integer

Expression Examples
expression result
+12 12
-100 -100
-123.4 -123.4
+'a' 97
-'a' -97
+"hello" raises an error
-null" raises an error


Complement Expressions

The complement operator performs a bitwise complement on its operand. The expression syntax, semantics, associativity and precedence are quite identical to the corresponding C and C++ expressions. This operator accepts only integer and char operands.
General Information
Operator ~
Type unary
Syntax ~ expr
Operand Types integer, char
Result Type integer
Functions bitwise complement

Expression Examples
expression result
~112 -113
~0 -1
~'a' -98
~2.3 raises an error
~"hello" raises an error

EyeDB manual