Skip to content

Floor ​

The greatest integer less than or equal to x: ⌊x⌋\lfloor x \rfloor.

✓ checked against that system · ! checked, with disagreements (hover a chip)WikipediaFloor and ceiling functionsFloor functionMathWorldFloorFunctionWikidataQ56860783FungrimFloor✓Fungrim entryWolfram LanguageFloor!
Floor(x)the greatest integer ≤x\le x, ⌊x⌋\lfloor x \rfloor.
SageMathenumeratio_floor(x)SymPyfloor(x)mpmathfloor(x)Oscarfloor(BigInt, x)Juliaenumeratio_floor(x)Rustfloor(x)
Floor(x, step)the greatest multiple of step at or below x.
Typed signatures
TypePackageApplies
(x: real | signed_infinity | ~oo, step: real?) -> real | signed_infinity | ~ooanalyticreplaces compute-enginealways
(x: real | signed_infinity | ~oo, step: real?) -> real | signed_infinity | ~oocompute-enginealways
(any, any?) -> anystructuresreplaces analyticalways

Domain: Arithmetic

Details
  • The greatest integer ≤x\le x: ⌊x⌋\lfloor x \rfloor.
  • Rounds toward −∞-\infty, not toward 0 -- so ⌊−3.5⌋=−4\lfloor -3.5 \rfloor = -4, not −3-3.
  • For a non-integer x, ⌈x⌉=⌊x⌋+1\lceil x \rceil = \lfloor x \rfloor + 1. See Ceil.
  • ⌊−x⌋=−⌈x⌉\lfloor -x \rfloor = -\lceil x \rceil.
  • Threads element-wise over a list.
  • A second argument floors to the nearest multiple of it -- the step needn't be an integer.
  • The second argument is a step, a multiple to floor to, as in Wolfram's Floor[x, a]: Floor(226,10)=220\mathrm{Floor}(226, 10) = 220. Round's second argument is a step too. Round breaks ties to even, as Wolfram does (see Round).

Examples

4 more kept as data, checked against the oracles
Basic #
live ↗
In⌊72⌋\lfloor\frac{7}{2}\rfloorOut33
live ↗
In⌊3.7⌋\lfloor3.7\rfloorOut33

Integers pass through unchanged

live ↗
In⌊5⌋\lfloor5\rfloorOut55

Threads element-wise over a list

live ↗
In⌊[1.2,−1.2,3.7]⌋\lfloor\bigl\lbrack1.2, -1.2, 3.7\bigr\rbrack\rfloorOut[1,−2,3]\bigl\lbrack1, -2, 3\bigr\rbrack
live ↗
In⌊2.4⌋\lfloor2.4\rfloorOut22
live ↗
In⌊2.6⌋\lfloor2.6\rfloorOut22
Scope #

Stays symbolic

live ↗
In⌊x⌋\lfloor x\rfloorOut⌊x⌋\lfloor x\rfloor

Exact radicals are decided numerically

live ↗
In⌊50⌋\lfloor\sqrt{50}\rfloorOut77

Evaluates at an exact constant: ⌊π⌋=3\lfloor\pi\rfloor = 3

live ↗
In⌊π⌋\lfloor π\rfloorOut33

...and at its negative, ⌊−π⌋=−4\lfloor -\pi \rfloor = -4

live ↗
In⌊−π⌋\lfloor-π\rfloorOut−4-4

A second argument floors to a multiple of it -- the nearest multiple of 10 below 226

live ↗
InFloor(226,10)\mathrm{Floor}(226, 10)Out220220

...the step needn't be an integer: 3.5⋅⌊−10.3/3.5⌋=−10.53.5 \cdot \lfloor -10.3/3.5 \rfloor = -10.5

live ↗
InFloor(−10.3,3.5)\mathrm{Floor}(-10.3, 3.5)Out−10.5-10.5

...nor rational: 2π−e≈3.572\pi - e \approx 3.57 floors to the multiple 5/25/2 of 5/45/4

live ↗
InFloor(2π−e,54)\mathrm{Floor}(2π-e, \frac{5}{4})Out52\frac{5}{2}

Floors the real and imaginary parts separately

live ↗
In⌊5.37−1.3i⌋\lfloor5.37-1.3i\rfloorOut5−2i5-2i

Threads entrywise over a matrix

live ↗
In⌊[[12,−1],[0,−12]]⌋\lfloor\bigl\lbrack\bigl\lbrack\frac{1}{2}, -1\bigr\rbrack, \bigl\lbrack0, -\frac{1}{2}\bigr\rbrack\bigr\rbrack\rfloorOut[[0,−1],[0,−1]]\bigl\lbrack\bigl\lbrack0, -1\bigr\rbrack, \bigl\lbrack0, -1\bigr\rbrack\bigr\rbrack

As a matrix function it agrees with entrywise floor on a triangular matrix

live ↗
InMatrixFunction(Floor,[[12,−1],[0,−12]])\mathrm{MatrixFunction}(\mathrm{Floor}, \bigl\lbrack\bigl\lbrack\frac{1}{2}, -1\bigr\rbrack, \bigl\lbrack0, -\frac{1}{2}\bigr\rbrack\bigr\rbrack)Out[[0,−1],[0,−1]]\bigl\lbrack\bigl\lbrack0, -1\bigr\rbrack, \bigl\lbrack0, -1\bigr\rbrack\bigr\rbrack

An integer is its own floor

live ↗
In⌊0⌋\lfloor0\rfloorOut00

Infinity passes through

live ↗
In⌊∞⌋\lfloor∞\rfloorOut∞∞

Two-argument floor to a multiple of 2: a branch per multiple, the zero stretch the default

live ↗
InPiecewiseExpand(Floor(x,2),0<x<4)\mathrm{PiecewiseExpand}(\mathrm{Floor}(x, 2), 0\lt x\lt4)OutPiecewise([[2,2≤x]],0)\mathrm{Piecewise}(\bigl\lbrack\bigl\lbrack2, 2≤x\bigr\rbrack\bigr\rbrack, 0)
live ↗
Ind⌊x⌋dx\frac{\mathrm{d}\lfloor x\rfloor}{\mathrm{d}x}Out00
Applications #

How many full 5-item packs fit in 17 items

live ↗
In⌊175⌋\lfloor\frac{17}{5}\rfloorOut33

Legendre's formula: 100!100! ends in ⌊100/5⌋+⌊100/25⌋=24\lfloor 100/5 \rfloor + \lfloor 100/25 \rfloor = 24 zeros

live ↗
In⌊1005⌋+⌊10025⌋\lfloor\frac{100}{5}\rfloor+\lfloor\frac{100}{25}\rfloorOut2424

The number of decimal digits of n is ⌊log⁡10n⌋+1\lfloor \log_{10} n \rfloor + 1

live ↗
In⌊log⁡10(12 345)⌋+1\lfloor\log_{10}(12\,345)\rfloor+1Out55

The first four digits of ee

live ↗
In⌊1 000e⌋\lfloor1\,000e\rfloorOut2 7182\,718

Extracts a digit of the decimal expansion of a fraction via modular power

live ↗
In⌊1997×10(PowerMod(10,999 999,997) mod 997)⌋\lfloor\frac{1}{997}×10(\mathrm{PowerMod}(10, 999\,999, 997)\bmod997)\rfloorOut22
Properties #

For a non-integer x, ⌈x⌉=⌊x⌋+1\lceil x \rceil = \lfloor x \rfloor + 1. See Ceil

live ↗
In⌊72⌋+1=⌈72⌉\lfloor\frac{7}{2}\rfloor+1=\lceil\frac{7}{2}\rceilOutTrue\mathrm{True}

⌊−x⌋=−⌈x⌉\lfloor -x \rfloor = -\lceil x \rceil

live ↗
In⌊−72⌋=−⌈72⌉\lfloor-\frac{7}{2}\rfloor=-\lceil\frac{7}{2}\rceilOutTrue\mathrm{True}

Idempotent: ⌊⌊x⌋⌋=⌊x⌋\lfloor\lfloor x \rfloor\rfloor = \lfloor x \rfloor, since the inner value is already an integer

live ↗
In⌊⌊x⌋⌋\lfloor\lfloor x\rfloor\rfloorOut⌊x⌋\lfloor x\rfloor

Largest multiple of 3 not above 16

live ↗
InFloor(16,3)\mathrm{Floor}(16, 3)Out1515

⌊x2⌋\lfloor x^2\rfloor on (0,2)(0, 2): a branch per integer, bounded by its square root

live ↗
InPiecewiseExpand(⌊x2⌋,0<x<2)\mathrm{PiecewiseExpand}(\lfloor x^2\rfloor, 0\lt x\lt2)OutPiecewise([[1,1≤x<21/2],[2,21/2≤x<31/2],[3,31/2≤x]],0)\mathrm{Piecewise}(\bigl\lbrack\bigl\lbrack1, 1≤x\lt2^{1/2}\bigr\rbrack, \bigl\lbrack2, 2^{1/2}≤x\lt3^{1/2}\bigr\rbrack, \bigl\lbrack3, 3^{1/2}≤x\bigr\rbrack\bigr\rbrack, 0)

Nested floors: the inner one is expanded first, then the outer one over its pieces

live ↗
InPiecewiseExpand(⌊x+13+⌊1−x/2⌋3⌋,−1<x<1)\mathrm{PiecewiseExpand}(\lfloor x+\frac{1}{3}+\lfloor1-x/2\rfloor^3\rfloor, -1\lt x\lt1)OutPiecewise([[1,2/3≤x∨−1/3≤x≤0]],0)\mathrm{Piecewise}(\bigl\lbrack\bigl\lbrack1, 2/3≤x∨-1/3≤x≤0\bigr\rbrack\bigr\rbrack, 0)

Integers are fixed points

live ↗
In⌊1⌋\lfloor1\rfloorOut11

Known value · Wolfram MathematicalFunctionData, Floor

A negative integer is unchanged

live ↗
In⌊−1⌋\lfloor-1\rfloorOut−1-1

Known value · Wolfram MathematicalFunctionData, Floor

The imaginary part −1-1 is already an integer

live ↗
In⌊−i⌋\lfloor-i\rfloorOut−i-i

Known value · Wolfram MathematicalFunctionData, Floor

Rounds down: ⌊2.3⌋=2\lfloor 2.3\rfloor = 2

live ↗
In⌊2310⌋\lfloor\frac{23}{10}\rfloorOut22

Known value · Wolfram MathematicalFunctionData, Floor

Negative integers are fixed

live ↗
In⌊−3⌋\lfloor-3\rfloorOut−3-3

Known value · Wolfram MathematicalFunctionData, Floor

Negatives round away from zero: ⌊−2.7⌋=−3\lfloor -2.7\rfloor=-3

live ↗
In⌊−2710⌋\lfloor-\frac{27}{10}\rfloorOut−3-3

Known value · Wolfram MathematicalFunctionData, Floor

Complex input: each part rounds down, 2−3i2-3i

live ↗
In⌊2310−ie⌋\lfloor\frac{23}{10}-ie\rfloorOut2−3i2-3i

Known value · Wolfram MathematicalFunctionData, Floor

live ↗
In2⌊23⌋+⌊1⌋2\lfloor\frac{2}{3}\rfloor+\lfloor1\rfloorOut11

Known value · Wolfram MathematicalFunctionData, Floor, FunctionalEquations

live ↗
In⌊12+102⌋\lfloor\frac{1}{2}+\frac{\sqrt{10}}{2}\rfloorOut22

Known value · Wolfram MathematicalFunctionData, Floor, FunctionalEquations

live ↗
In⌊2+3⌋\lfloor\sqrt{2}+\sqrt{3}\rfloorOut33

Known value · Wolfram MathematicalFunctionData, Floor, FunctionalEquations

live ↗
In⌊1⌋+⌊56⌋+⌊76⌋\lfloor1\rfloor+\lfloor\frac{5}{6}\rfloor+\lfloor\frac{7}{6}\rfloorOut22

Known value · Wolfram MathematicalFunctionData, Floor, FunctionalEquations

Possible issues #

Rounds toward −∞-\infty, not toward 0: floor(-3.2) is -4, not -3

live ↗
In⌊−3.2⌋\lfloor-3.2\rfloorOut−4-4

Infinities pass through unchanged

live ↗
In⌊−∞⌋\lfloor-∞\rfloorOut−∞-∞
About
Examples48
Checked againstWolfram Language 46 agree2 differSageMath 38 agree1 unevaluated1 errorSymPy 39 agree1 differ1 unevaluatedmpmath 21 agree1 errorOscar 19 agreeJulia 32 agree4 errorRust 29 agree2 error
CrosswalkWikipedia ×2MathWorldWikidataFungrimFungrim entry ×12Wolfram LanguageSageMathSymPympmathOscarJuliaRust

Implementation

mappedoscarpackages/oracle/src/mappings.ts
mappedwolframpackages/oracle/src/mappings.ts
mappedsympypackages/oracle/src/mappings.ts
mappedmpmathpackages/oracle/src/mappings.ts
mappedsagepackages/oracle/src/mappings.ts
mappedrustpackages/oracle/src/mappings.ts
mappedjuliapackages/oracle/src/mappings.ts

See also: Ceil, Round