Propeller Manual

Table Of Contents
2: Spin Language Reference – CON
Propeller Manual v1.1 · Page 87
For run-time floating-point operations, the FloatMath, FloatString, Float32, and Float32Full
objects provide math functions compatible with single-precision numbers.
See
FLOAT on page , ROUNDT 108 on page 198, TRUNC on page 209, and the FloatMath,
FloatString, Float32, and Float32Full objects for more information.
Enumerations (Syntax 2 and 3)
Constant Blocks can also declare enumerated constant symbols. Enumerations are logically
grouped symbols which have incrementing integer constant values assigned to them that are
each unique for the group. For example, an object may have the need for certain modes of
operation. Each of these modes can be identified by a number, 0, 1, 2 and 3, for example.
The numbers themselves don’t really matter for our purposes; they just need to be unique
within the context of the operation mode. Since the numbers themselves are not descriptive,
it may be difficult to remember what mode 3 does, but it is a lot easier to remember what the
mode means if it had a descriptive name instead. Look at the following example.
CON
'Declare modes of operation
RunTest = 0
RunVerbose = 1
RunBrief = 2
RunFull = 3
The above example would suffice for our purposes; now users of our object can indicate
RunFull” instead of “3” to specify the desired mode of operation. The problem is, defining a
logical group of items this way may cause bugs and maintenance problems because if any
value was changed (on purpose or by accident) without changing the rest accordingly, it may
cause the program to fail. Also, imagine a case where there were 20 modes of operation.
That would be a much longer set of constants and even more opportunities for maintenance
issues.
Enumerations solve these problems by automatically incrementing values for symbols. We
can rewrite the above example with enumeration syntax as follows:
CON 'Declare modes of operation
#0, RunTest, RunVerbose, RunBrief, RunFull
Here, #0, tells the compiler to start counting from the number 0 and it sets the next symbol
equal to that value. Then, any additional symbols that do not specify their own value (via an
‘= expression’) are automatically assigned the previous value plus 1. The result is that
RunTest equals 0, RunVerbose equals 1, RunBrief equals 2 and RunFull equals 3. For most