Propeller Manual

Table Of Contents
FLOAT – Spin Language Reference
Page 108 · Propeller Manual v1.1
FLOAT
Directive: Convert an integer constant expression to a compile-time floating-point value.
((CON VAR OBJ PUB PRI DAT))
FLOAT (IntegerConstant )
Returns: Resolved value of integer constant expression as a floating-point number.
IntegerConstant is the desired integer constant expression to be used as a constant
floating-point value.
Explanation
FLOAT is one of three directives (T FLOAT, ROUND and TRUNC) used for floating-point constant
expressions. The
FLOATT directive converts a constant integer value to a constant floating-
point value.
Using FLOAT
While most constants are 32-bit integer values, the Propeller compiler supports 32-bit
floating-point values and constant expressions for compile-time use. Note that this is for
constant expressions only, not run-time variable expressions.
For typical floating-point constant declarations, the expression must be shown as a floating-
point value in one of three ways: 1) as an integer value followed by a decimal point and at
least one digit, 2) as an integer with an E followed by an exponent value, or 3) both 1 and 2.
For example:
CON
OneHalf = 0.5
Ratio = 2.0 / 5.0
Miles = 10e5
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.
Notice that in the above example, every component of every expression is shown as a
floating-point value. Now take a look at the following example:
CON
Two = 2
Ratio = Two / 5.0