INTEGER [truncate | floor | ceiling | round] inputVector resultVariable

Converts each element of the inputVector to integer in the manner dictated by the optional keyword used and stores the resulting integers in resultVariable. If the keyword is omitted, it is defaulted to truncate.

There are four different ways to convert a floating point number to an integer.

  • Truncate: this conversion simply removes any fractional part from the number. A number like 1.65 truncates to 1.0; -1.65 truncates to -1.0. This is the default if keyword is omitted.

  • Floor: this conversion chooses the largest (closest to positive infinity) integer that is not greater than the original number. The floor of 1.65 is 1.0; the floor of -1.65 is -2.0

  • Ceiling: This conversion chooses the smallest (closest to negative infinity) integer that is not smaller than the original number. The ceiling of 1.65 is 2.0; the ceiling of -1.65 is -1.0.

  • Round: This conversion chooses the integer closest to the original number. If two possible integers are equally close, the one that is even is chosen. This has the effect of a 50 percent chance of rounding down and a 50 percent chance of rounding up. Note that this is different from the rounding policy of the ROUND command.

If no keyword is present, the default conversion is truncate.

Missing values (NaN or .) are unchanged by any of the conversion options. Zero is unchanged by any of the conversion options.

Usage with the LET command

The four different versions of INTEGER can be used as functions in the LET command but since LET doesn't accept keywords, each version is given its own name. These names are: INTEGER_TRUNCATE, INTEGER_FLOOR, INTEGER_CEILING, and INTEGER_ROUND. These names do not work as separate commands; they only work in the LET command.

Since the default behavior of the INTEGER command is to truncate, you can use the name INTEGER as a synonym of INTEGER_TRUNCATE within a LET command.

See also: ROUND, FRACTION, and LET

The following program shows the various INTEGER options in action:

COPY (5.5 6.5 -1.5 1.5 1.9 -1.9 0 NaN) inVec
INTEGER truncate inVec Trunc
INTEGER floor inVec Floor
INTEGER ceiling inVec Ceil
INTEGER round inVec Round
PRINT table inVec trunc2 floor ceil round

Which has the output:

inVec           Trunc           Floor           Ceil          Round         
5.5             5               5               6             6             
6.5             6               6               7             6             
-1.5            -1              -2              -1            -2            
1.5             1               1               2             2             
1.9             1               1               2             2             
-1.9            -1              -2              -1            -2            
0.0E00          0.0E00          0.0E00          0.0E00        0.0E00
NaN             NaN             NaN             NaN           NaN