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 ]
{"ft_lang_label":"__label__en","ft_lang_prob":0.863309,"math_prob":0.9113365,"size":2332,"snap":"2021-31-2021-39","text_gpt3_token_len":778,"char_repetition_ratio":0.13573883,"word_repetition_ratio":0.10672854,"special_character_ratio":0.3254717,"punctuation_ratio":0.11342155,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95665735,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-16T19:08:03Z\",\"WARC-Record-ID\":\"<urn:uuid:2ef2e6cc-1ac8-4ae1-87fa-2be933453f2f>\",\"Content-Length\":\"6628\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:dfc296f3-b9d4-463b-bf44-8cef50d4255b>\",\"WARC-Concurrent-To\":\"<urn:uuid:384c6e74-1b5a-47df-be7b-9ad849655ad8>\",\"WARC-IP-Address\":\"85.233.160.141\",\"WARC-Target-URI\":\"https://microapl.com/apl_help/ch_020_020_110.htm\",\"WARC-Payload-Digest\":\"sha1:FZ2GXLCESOZBQLPOTCBECFWNT6I7OIRM\",\"WARC-Block-Digest\":\"sha1:LB3XYQCJORZE52HT54IGZZOGYUFHU5QM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780053717.37_warc_CC-MAIN-20210916174455-20210916204455-00320.warc.gz\"}"}