Floor: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - "<source" to "<syntaxhighlight")
m (Text replacement - "</source>" to "</syntaxhighlight>")
Tags: Mobile edit Mobile web edit
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]] <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.
{{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>⌊</syntaxhighlight> 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 8: Line 8:
       ⌊2 2.8 ¯2 ¯2.8
       ⌊2 2.8 ¯2 ¯2.8
2 2 ¯2 ¯3
2 2 ¯2 ¯3
</source>
</syntaxhighlight>


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.
Line 15: Line 15:
       ⌊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
</source>
</syntaxhighlight>


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.
Line 22: Line 22:
       ⌊10 20 30÷3
       ⌊10 20 30÷3
3 6 10
3 6 10
</source>
</syntaxhighlight>


== Properties ==
== Properties ==
Line 36: Line 36:
       ⌊v
       ⌊v
0 1 1
0 1 1
</source>
</syntaxhighlight>


=== Complex floor ===
=== Complex floor ===
Line 50: Line 50:
       1>|v-⌊v
       1>|v-⌊v
1 1 1 1
1 1 1 1
</source>{{Works in|[[Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[Dyalog APL]]}}


== External links ==
== External links ==

Revision as of 22:19, 10 September 2022

Floor () is a monadic scalar function that gives the floor of a real number, that is, the greatest integer 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 with the dyadic arithmetic function Minimum. Traditional mathematics derives its notation and name for floor from APL.

Examples

Floor rounds down the given numbers to the nearest integers.

      ⌊2 2.8 ¯2 ¯2.8
2 2 ¯2 ¯3

Rounding to the nearest integer (rounding up on half) can be achieved by adding 0.5 before applying Floor.

      ⌊0.5+2 2.3 2.5 2.8
2 2 3 3

Integral quotient of division can be found with division followed by Floor.

      ⌊10 20 30÷3
3 6 10

Properties

The floor of any real number is an integer.

Floor is affected by comparison tolerance. If the given number is tolerantly equal to its ceiling, it is rounded to that number instead.

      ⎕PP←16
      ⎕←v←1+0.6×⎕CTׯ2 ¯1 0
0.999999999999988 0.999999999999994 1
      ⌊v
0 1 1

Complex floor

Main article: Complex Floor

Eugene McDonnell designed the domain extension of Floor to complex numbers.[1] Complex floor maps every complex number to a Gaussian integer, a complex number whose real and imaginary parts are integers. It has an important property that the magnitude of 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.

      v←1.8J2.5 2.2J2.5 2.5J2.2 2.5J1.8
      ⌊v
2J2 2J2 2J2 2J2
      1>|v-⌊v
1 1 1 1
Works in: Dyalog APL

External links

Documentation

References

  1. McDonnell, Eugene. "Complex Floor".
APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector