Topic: `APLX Help` : `Help on APL language` : `APL Primitives` : `⌊ Floor`
[ Previous | Next | Contents | Index | APL Home ] # `⌊` Floor

The number or numbers in the right-hand argument are rounded down to the next whole number.

```             ⌊ 45.9
45
⌊ ¯2.3                   (Note the effect on a negative number)
¯3
⌊ 1.2 ¯0.3 99.1 2.8      (Each number in a vector is rounded
1 ¯1 99 2                       down)
⌊0.5+1.2 ¯0.3 99.1 2.8   (0.5 is added to each number before
1 0 99 3                        ⌊ is applied to it, ensuring 'true'
rounding)
TABLE
62.8  3.0  ¯2.9
9.1  7.3   0.01
⌊ TABLE                  (Each number in TABLE is rounded down)
62  3 ¯3
9  7  0
⌊(¯0.1 ¯10.1 11.3 7.4) ( 2 2⍴¯0.3 2.8 99.1 ¯2.3)
¯1 ¯11 11 7    ¯1  2          (Each element is rounded down)
99 ¯3
```

### Comparison tolerance

When acting on a number which is very close to but slightly smaller than an integer, Floor may round up to that integer rather than round down. This will happen if the argument is within comparison tolerance of the integer, and is therefore considered in APL to be equal to it.

### Effect on internal representation

If the argument to Floor or Ceiling is an array which is held internally in boolean or integer form, then the result will always be represented in integer form and the numbers in the array will be unchanged.

If the argument to Floor or Ceiling is internally in floating-point form, then in general, provided all the numbers within the argument are in the range of numbers which can be represented as integers, the result will internally be represented as integers rather than floating points. Floor or Ceiling can therefore be used to force the internal representation of numbers to integer form:

```      X←3.0 100.0 ¯20.0
⎕DR X
3
Y←⌊X
⎕DR Y
2
X
3 100 ¯20
Y
3 100 ¯20
X=Y
1 1 1
```

In this example, X is held internally in floating-point format, but Y is held internally in integer format. The values of the array elements are, however, equal.

See `⎕DR` for more information on data representation.

### Differences between 32-bit and 64-bit implementations of APLX

In the 32-bit version of APLX, numbers can be represented as integers if they are in the range `¯2147483648` to `2147483647`. If the argument to Floor or Ceiling contains numbers which round to numbers outside this range, the result will internally be represented in floating-point format.

In the 64-bit APLX64 interpreter, numbers can be represented as integers if they are in the range `¯9223372036854775808` to `9223372036854775807`. However, the floating-point representation of a number is limited to 53 bits of precision, which is equivalent to saying that at `2*53` and above, several integers all map to the same floating-point representation. For this reason, if the argument to Floor or Ceiling is in floating-point form, and contains numbers whose magnitude is equal to or greater than `2*53`, the result will be left in floating-point form so as not to introduce a spurious precision to numbers which are inherently imprecise.

In this example using APLX64, `X` is represented internally as a 64-bit integer, and `Y` is represented internally as a floating-point number:

```      X←2*53
X
9007199254740992
⎕DR X
2
Y←X×1.0
Y
9.007199255E15
⎕DR Y
3
⌊Y
9.007199255E15
⎕DR ⌊Y
3
⌊Y-1
9007199254740991
⎕DR ⌊Y-1
2
```

Topic: `APLX Help` : `Help on APL language` : `APL Primitives` : `⌊ Floor`
[ Previous | Next | Contents | Index | APL Home ]