BrightSign HD2000 BrightScript Reference Guide User Manual

Page 9

Advertising
background image

9


Examples:

1.234567 - float
5 - int
1.0 - float
1.0# - double
12345678900 - double
1% - int
1! - float
1# - double
1E0 – float
1D0 – double
1.1% -- syntax error

Type Conversion (Promotion)

When operations are performed on one or two numbers, the result must be typed as integer, double or
single-precision (float). When a +, -, or * operation is performed, the result will have the same degree of
precision as the most precise operand. For example, if one operand is single-precision, and the other
double-precision, the result will be double precision. Only when both operands are integers will a result be
integer. If the result of an integer *, -, or + operation is outside the integer range, the operation will be done in
double precision and the result will be double precision.

Division follows the same rules as +, * and -, except that it is never done at the integer level: when both
operators are integers, the operation is done in single precision float with a single-precision float result.
During a compare operation (< , >,=,etc.) the operands are converted to the same type before they are
compared. The less precise type will always be converted to the more precise type.

The logical operators AND, OR and NOT first convert their operands to integer form. The result of a logical
operation is always an integer.

Effects of Type Conversions on Accuracy

When a number is converted to integer type, it is "rounded down"; i.e., the largest integer, which is not
greater than the number is used. (This is the same thing that happens when the INT function is applied to the
number.)

When a number is converted from double to single precision, it is "4/5 rounded" (the least significant digit is
rounded up if the fractional part > =5. Otherwise, it is left unchanged).

When a single precision number is converted to double precision, only the seven most significant digits will
be accurate.
Examples:
10 A!=1.3
20 A#=A!
30 PRINT A#

RUN
1.299999952316284

10 A#=2/3
20 PRINT A#

Advertising
This manual is related to the following products: