Propeller Manual

Table Of Contents
2: Spin Language Reference – FLOAT
Propeller Manual v1.1 · Page 109
Here, Two is defined as an integer constant and Ratio appears to be defined as a floating-point
constant. This causes an error on the
Ratio line because, 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 directive to convert an integer value to a floating-point
value, such as in the following:
T
CON
Two = 2
Ratio = float(Two) / 5.0
The FLOAT directive in this example converts the integer constant, Two, into the floating-point
form of that value so that it can be used in the floating-point expression.
T
About Floating Point
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.
Floating-point constant expressions can be defined and used for many compile-time purposes,
but for run-time floating-point operations, the FloatMath, FloatString, Float32, and
Float32Full objects provide math functions compatible with single-precision numbers.
See Constant Assignment ‘=’ in the Operators section on page 148,
ROUND on page 198, and
TRUNC on page 209, as well as the FloatMath, FloatString, Float32, and Float32Full objects
for more information.