4,494
edits
(→Documentation: BQN) |
m (Text replacement - "<source" to "<syntaxhighlight") |
||
Line 1: | Line 1: | ||
{{Built-in|Floor|⌊}} is a [[monadic]] [[scalar function]] that gives the [[wikipedia:floor and ceiling functions|floor]] of a real number, that is, the greatest integer [[Comparison tolerance|tolerantly]] [[less than or equal to]] the given value. This operation is also known as '''integral part''', '''entier''', and '''round down'''. Floor shares the [[glyph]] < | {{Built-in|Floor|⌊}} is a [[monadic]] [[scalar function]] that gives the [[wikipedia:floor and ceiling functions|floor]] of a real number, that is, the greatest integer [[Comparison tolerance|tolerantly]] [[less than or equal to]] the given value. This operation is also known as '''integral part''', '''entier''', and '''round down'''. Floor shares the [[glyph]] <syntaxhighlight lang=apl inline>⌊</source> with the dyadic arithmetic function [[Minimum]]. [[Comparison_with_traditional_mathematics#Prefix|Traditional mathematics]] derives [[Ken_Iverson#Floor_and_Ceiling|its notation]] and name for floor from APL. | ||
== Examples == | == Examples == | ||
Line 5: | Line 5: | ||
Floor rounds down the given numbers to the nearest integers. | Floor rounds down the given numbers to the nearest integers. | ||
< | <syntaxhighlight lang=apl> | ||
⌊2 2.8 ¯2 ¯2.8 | ⌊2 2.8 ¯2 ¯2.8 | ||
2 2 ¯2 ¯3 | 2 2 ¯2 ¯3 | ||
Line 12: | Line 12: | ||
Rounding to the ''nearest'' integer (rounding up on half) can be achieved by [[add|adding]] 0.5 before applying Floor. | Rounding to the ''nearest'' integer (rounding up on half) can be achieved by [[add|adding]] 0.5 before applying Floor. | ||
< | <syntaxhighlight lang=apl> | ||
⌊0.5+2 2.3 2.5 2.8 | ⌊0.5+2 2.3 2.5 2.8 | ||
2 2 3 3 | 2 2 3 3 | ||
Line 19: | Line 19: | ||
Integral quotient of division can be found with [[divide|division]] followed by Floor. | Integral quotient of division can be found with [[divide|division]] followed by Floor. | ||
< | <syntaxhighlight lang=apl> | ||
⌊10 20 30÷3 | ⌊10 20 30÷3 | ||
3 6 10 | 3 6 10 | ||
Line 30: | Line 30: | ||
Floor is affected by [[comparison tolerance]]. If the given number is [[tolerant comparison|tolerantly equal]] to its [[ceiling]], it is rounded to that number instead. | Floor is affected by [[comparison tolerance]]. If the given number is [[tolerant comparison|tolerantly equal]] to its [[ceiling]], it is rounded to that number instead. | ||
< | <syntaxhighlight lang=apl> | ||
⎕PP←16 | ⎕PP←16 | ||
⎕←v←1+0.6×⎕CTׯ2 ¯1 0 | ⎕←v←1+0.6×⎕CTׯ2 ¯1 0 | ||
Line 44: | Line 44: | ||
[[Eugene McDonnell]] designed the domain extension of Floor to [[complex number|complex numbers]].<ref>McDonnell, Eugene. [https://www.jsoftware.com/papers/eem/complexfloor.htm "Complex Floor"].</ref> Complex floor maps every complex number to a [[wikipedia:Gaussian integer|Gaussian integer]], a complex number whose real and imaginary parts are integers. It has an important property that the [[magnitude]] of [[subtract|difference]] between any complex number Z and its floor is [[less than]] 1. This extension is currently implemented in [[Dyalog APL]], [[J]], and [[NARS2000]], and is internally used to implement complex [[ceiling]], [[residue]], and [[GCD]]. | [[Eugene McDonnell]] designed the domain extension of Floor to [[complex number|complex numbers]].<ref>McDonnell, Eugene. [https://www.jsoftware.com/papers/eem/complexfloor.htm "Complex Floor"].</ref> Complex floor maps every complex number to a [[wikipedia:Gaussian integer|Gaussian integer]], a complex number whose real and imaginary parts are integers. It has an important property that the [[magnitude]] of [[subtract|difference]] between any complex number Z and its floor is [[less than]] 1. This extension is currently implemented in [[Dyalog APL]], [[J]], and [[NARS2000]], and is internally used to implement complex [[ceiling]], [[residue]], and [[GCD]]. | ||
< | <syntaxhighlight lang=apl> | ||
v←1.8J2.5 2.2J2.5 2.5J2.2 2.5J1.8 | v←1.8J2.5 2.2J2.5 2.5J2.2 2.5J1.8 | ||
⌊v | ⌊v |