Propeller Manual

Table Of Contents
2: Spin Language Reference – Operators
Propeller Manual v1.1 · Page 149
The above code creates three floating-point constants. OneHalf is equal to 0.5, Ratio is equal
to 0.4 and
Miles is equal to 1,000,000. Note that if Ratio were defined as 2 / 5 instead of 2.0
/ 5.0, the expression would be treated as an integer constant and the result would be an integer
constant equal to 0. For floating-point constant expressions, every value within the
expression must be a floating-point value; you cannot mix integer and floating-point values
like Ratio = 2 / 5.0. You can, however, use the
FLOAT declaration to convert an integer value
to a floating-point value, such as
Ratio = FLOAT(2) / 5.0.
T
The Propeller compiler handles floating-point constants as a single-precision real number as
described by the IEEE-754 standard. Single-precision real numbers are stored in 32 bits, with
a 1-bit sign, an 8-bit exponent, and a 23-bit mantissa (the fractional part). This provides
approximately 7.2 significant decimal digits.
For run-time floating-point operations, the FloatMath and FloatString objects provide math
functions compatible with single-precision numbers.
See
FLOAT, page 108; ROUND, page 198; TRUNC, page 209, as well as the FloatMath and
FloatString objects for more information.
Variable Assignment ‘
:=
The Variable Assignment operator is used only within methods (
PUB and PRI blocks), to
assign a value to a variable. For example,
Temp := 21
Triple := Temp * 3
At run time this code would set the Temp variable equal to 21 and set Triple to 21 * 3, which
is 63.
As with other assignment operators, the Variable Assignment operator can be used within
expressions to assign intermediate results, such as:
Triple := 1 + (Temp := 21) * 3
This example first sets Temp to 21, then multiplies Temp by 3 and adds 1, finally assigning the
result, 64, to
Triple.
Add ‘
+’, ‘+=
The Add operator adds two values together. Add can be used in both variable and constant
expressions. Example:
X := Y + 5