Datatype promotion when evaluating numeric expressions

Order of precedence

The PocketBuilder numeric datatypes are listed here in order of highest to lowest precedence (the order is based on the range of values for each datatype):

Rules for type promotion

Datatypes of operands If operands in an expression have different datatypes, the value whose type has lower precedence is converted to the datatype with higher precedence.

Unsigned versus signed Unsigned has precedence over signed, so if one operand is signed and the other is unsigned, both are promoted to the unsigned version of the higher type. For example, if one operator is a long and another UnsignedInteger, both are promoted to UnsignedLong.

Operators The effects of operators on an expression’s datatype are:

Datatypes of literals

When a literal is an operand in an expression, its datatype is determined by the literal’s value. The datatype of a literal affects the type promotion of the literal and other operands in an expression.

Table 4-5: Datatypes of literal operands in an expression

Literal

Datatype

Integer literals (no decimal point or exponent) within the range of Long

Long

Integer literals beyond the range of Long and within the range of UnsignedLong

UnsignedLong

Integer literals beyond the range of UnsignedLong and within the range of LongLong

UnsignedLong

Numeric literals with a decimal point (but no exponent)

Decimal

Numeric literals with a decimal point and explicit exponent

Double

NoteOut of range Integer literals beyond the range of LongLong cause compiler errors.