Vocabulary/ltdot
>> << Down to: Dyad Back to: Vocabulary Thru to: Dictionary
<. y Floor
Rank 0 -- operates on individual atoms of y, producing a result of the same shape -- WHY IS THIS IMPORTANT?
The floor of y i.e. the largest integer less than or equal to y
<. 4.6 4 <. 4.2 4.5 4.6 4 4 4 <. 4.6 4 _4 _4.6 4 4 _4 _5
The result of <. y may not have integer type.
If y is too large or too small to be represented as an integer, it will be left in floating point form. Furthermore, <. y is always complex for complex y.
Floor (<.) uses tolerant comparison. <. y is y rounded towards -∞, except that if y is tolerantly equal to an integer, <. y is that integer. For more information, read about tolerant floor and ceiling. To require exact comparison, use (<.!.0) in place of (<.) to temporarily set the comparison tolerance to zero.
<. 100.999999999999 NB. tolerant floor of y can be greater than y! 101 <.!.0 (100.999999999999) 100
Common uses
1. Test whether numbers are integers or not.
can also use Ceiling (>.)
3 3.14 5 = <. 3 3.14 5 1 0 1
2. Convert floating point representations of integers (8 bytes per value) to integers (4 bytes per value) in order to save memory
Such values can arise as a result of arithmetic operations like Divide (%)
] N=: 27 % 9 3 datatype N floating ] n=: <. 27 % 9 NB. alternatively: n=: 27 <.@:% 9 3 datatype n integer
3. Round fractional z to the nearest integer
z=: 4.2 4.5 4.6 <. 0.5 + z 4 5 5
Details
<. y uses tolerant comparison, which means an integer is considered equal to y if its difference from y is less than the y*tolerance. If y is so big that y*tolerance is greater than 1, results can be surprising: the largest integer tolerantly equal to y could be considerably larger than y. The implementation defines <. y as the integer closest to y, if that integer is tolerantly equal to y; otherwise the next-lower integer.
Related Primitives
Ceiling (>. y)
More Information
Complex Floor
For purposes of <. y, the complex plane is tiled into rectangles tilted 45 degrees with respect to the real and complex axes. The sides running northwest-to-southeast have length (%:2), while the sides running northeast-to-southwest have half that length. This makes the area of each rectangle 1. The north and east vertices of each rectangle are on Gaussian integers (i. e. points with integral real and imaginary parts). The west and south vertices are each in the center of a square made up of 4 Gaussian integers. In the center of the southwest edge is the Gaussian integer at (northvertex-0j1) and (eastvertex-1j0). This southwest Gaussian integer is the value associated with the rectangle, and any point inside the rectangle is rounded to the southwest point.
NB. The rectangle associated with the origin has vertices 0j1, _0.5j0.5, 0.5j_0.5, 1j0 <. _0.1j0.5 NB. All these points are inside... 0 <. 0.1j0.5 0 <. 0.4j0.4 0 <. 0.7j0.2 0 <. 0.7j_0.2 0 <. 0.2j0.7 0 <. 0.7j0.4 NB. ...but this is outside 1 <. 0.5j0.6 NB. this one too 0j1
Tolerant comparison enters the picture in two places. The sequence for calculating the floor is as follows:
- The base point to use is calculated as the (tolerant) floor of the real and imaginary parts separately.
- Two lines are drawn through the 1x1 square whose lower-left corner is the base point, and y is classified with respect to these lines.
y might be slightly outside the square as a result of tolerance, but that's OK.- A line a drawn from the bottom-left to the top-right corner of the square, and y is marked 'southeast' if it lies on or below the line. This test is intolerant.
The model in the J Dictionary incorrectly shows this test as tolerant. - A line is drawn from the top-left to the bottom-right corner of the square, and y is marked 'southwest' if it lies below the line. This test is tolerant (i. e. points very close to the line are not southwest).
- A line a drawn from the bottom-left to the top-right corner of the square, and y is marked 'southeast' if it lies on or below the line. This test is intolerant.
- The complex floor is the base point if y is southwest; base point + 1j0 if southeast but not southwest; base point + 0j1 if neither southeast nor southwest.
<. 0.6j0.4 NB. Right on the line, southeast and southwest 1 <. 0.6j0.3999999999999999 NB. southeast and tolerantly northeast... 1 (<.!.0) 0.6j0.3999999999999999 NB. ...but intolerantly southwest 0
Differences between complex floor and real floor
The complex floor model described above is used for all numbers with complex data type as given by 3!:0. This means that complex numbers with zero imaginary parts may respond to <. y differently from equivalent real numbers:
<.x0 =: _1e_14 NB. Not tolerantly equal to 0 _1 <.x1 =: _1e_14 j. 0 NB. But close enough for complex floor 0 x0 =!.0 x1 1
Further information:
COMPLEX FLOOR, Eugene McDonnell, IBM Scientific Center, Philadelphia [1] COMPLEX FLOOR REVISITED, Doug Forkes, I. P. Sharp Associates [2]
Use These Combinations
Combinations using <. y that have exceptionally good performance include:
What it does Type;
Precisions;
RanksSyntax Variants;
Restrictions
Benefits;
Bug Warnings
Integer-result operations extended integer <.@f y
x <.@f y
(f is any verb)<. in place of >. Avoids non-integer intermediate results Integer divide integer x <.@% y
x >.@% y
@: in place of @ uses integer division
x <. y Lesser of (Min)
Rank 0 0 -- operates on individual atoms of x and y, producing a result of the same shape -- WHY IS THIS IMPORTANT?
The lesser atoms of x and y
3 <. 4 3 3 <. 4 _4 3 _4 2 3 <. 4 1 2 1
Common uses
1. Find the minimum value in a list
Use in conjunction with Insert (/)
<./ 7 8 5 9 2 2
2. Find the running minimum in a list (scanned from left to right)
Use in conjunction with Insert (/) and Prefix (\)
<./\ 7 8 5 9 2 7 7 5 5 2
Related Primitives
Larger Of (Max) (x >. y)
More Information
1. If an argument to x <. y is complex, its imaginary part must be tolerantly equal to 0, using the default tolerance of 2^_44 even if the comparison x <. y itself uses a different tolerance. The result will have floating-point precision.
2. If x <. y has arguments of different precisions, the arguments are converted to the higher-priority precision as described here. The conversion may turn an argument into a smaller or larger value, especially if a large 64-bit integer is converted to floating-point.
<. 9223372036854765500 <. 1e19 9223372036854765568 <. 9223372036854765580 <. 1e19 9223372036854765568
Use These Combinations
Combinations using x <. y that have exceptionally good performance include:
What it does Type;
Precisions;
RanksSyntax Variants;
Restrictions
Benefits;
Bug Warnings
Find index of first/last occurrence of largest/smallest value integer or floating-point list (i. <./) y
(i. >./) y
or i: it actually does (i. >.!.0/) etc.; is faster than 0 ({ /:~) y Reductions on infixes Boolean, integer, floating-point x +/\ y <. >. in place of + much faster than alternatives Boolean reductions on partitions Boolean x +//. y = <. >. +. * *. ~: in place of + avoids building argument cells Reductions on partitions integer, floating-point x +//. y <. >. in place of + avoids building argument cells Max/min along diagonals non-complex numeric >.//. y <. in place of >. avoids building argument cells Integer-result operations extended integer <.@f y
x <.@f y
(f is any verb)<. in place of >. Avoids non-integer intermediate results Integer divide integer x <.@% y
x >.@% y
@: in place of @ uses integer division