Propeller Manual

Table Of Contents
ROUND – Spin Language Reference
ROUND
Directive: Round a floating-point constant to the nearest integer.
((CON VAR OBJ PUB PRI DAT))
ROUND ( FloatConstant )
Returns: Nearest integer to original floating-point constant value.
FloatConstant is the floating-point constant expression to be rounded to the nearest
integer.
Explanation
ROUND is one of three directives (FLOAT, ROUND and TRUNC) used for floating-point constant
expressions.
ROUND returns an integer constant that is the closest integer value to the given
floating-point constant expression. Fractional values of ½ (.5) or higher are rounded up to the
nearest whole number while lower fractions are rounded down.
Using ROUND
ROUND can be used to round floating-point constants up or down to the nearest integer value.
Note that this is for compile-time constant expressions only, not run-time variable
expressions. For example:
CON
OneHalf = 0.5
Smaller = 0.4999
Rnd1 = round(OneHalf)
Rnd2 = round(Smaller)
Rnd3 = round(Smaller * 10.0) + 4
The above code creates two floating-point constants, OneHalf and Smaller, equal to 0.5 and
0.4999, respectively. The next three constants,
Rnd1, Rnd2 and Rnd3, are integer constants
that are based on
OneHalf and Smaller using the ROUND directive. Rnd1 = 1, Rnd2 = 0, and
Rnd3 = 9.
About Floating-Point Constants
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
Page 198 · Propeller Manual v1.1