Invalid object return, Dynamic typing for numbers, Number type conversion – BrightSign BrightScript 3.0 Reference Manual User Manual

Page 13

Advertising
background image

8

Invalid Object Return

Many methods (i.e. functions) that return objects can also return Invalid (for example, in cases where there is no object to
return). In these cases, the variable accepting the result must be dynamically typed since it may be assigned either type.

Example: The following code will return a type mismatch:

a$ is a string that has a string type declaration, and thus it

cannot contain Invalid.
l=[]
a$=l.pop()

Dynamic Typing for Numbers

The following rules determine how integers, doubles, and floats are dynamically typed:

1. If a constant contains 10 or more digits, or if

D is used in the exponent, the number is Double. Adding a # type

declaration also forces a constant to be a Double.

2. If the number is not double precision and it contains a decimal point, the number is a Float. Expressing a number in

scientific notation using the

E exponent also forces a constant to be a Float.

3. If neither of the above conditions is true for a constant, the number is an Integer.

Number Type Conversion

When operations are performed on one or two numbers, the result must be typed as an Integer, Float, or Double. When
an addition (+), subtraction (-), or multiplication (*) operation is performed, the result will have the same degree of
precision as the most precise operand: For example, multiplying an Integer by a Double will return a number that is a
Double.

Only when both operands are Integers will the result be an Integer number. If the result of two Integer operands is outside
the 32-bit range, the operation and return will be carried out with Doubles.

Advertising