Home      Discussion      Topics      Dictionary      Almanac
Signup       Login
Floor function

Floor function

Overview
In mathematics
Mathematics
Mathematics is the science and study of quantity, structure, space, and change. Mathematicians seek out patterns, formulate new conjectures, and establish truth by rigorous deduction from appropriately chosen axioms and definitions....

 and computer science
Computer science
Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems. It is frequently described as the systematic study of algorithmic processes that create, describe and transform...

, the floor and ceiling function
Function (mathematics)
In mathematics, a function is a relation between a given set of elements and another set of elements , which associates each element in the domain with exactly one element in the codomain...

s map a real number
Real number
In mathematics, the real numbers include both rational numbers, such as 42 and −23/129, and irrational numbers, such as pi and the square root of two; or, a real number can be given by an infinite decimal representation, such as 2.4871773339..., where the digits continue in some way; or, the real...

 to the next smallest or next largest integer
Integer
The integers are natural numbers including 0 and their negatives . They are numbers that can be written without a fractional or decimal component, and fall within the set {.....

. More precisely, floor(x) is the largest integer not greater than x and ceiling(x) is the smallest integer not less than x.

Gauss
Carl Friedrich Gauss
Johann Carl Friedrich Gauss was a German mathematician and scientist who contributed significantly to many fields, including number theory, statistics, analysis, differential geometry, geodesy, geophysics, electrostatics, astronomy and optics...

 introduced the square bracket notation [x] for the floor function in his third proof of quadratic reciprocity
Quadratic reciprocity
The law of quadratic reciprocity is a theorem from modular arithmetic, a branch of number theory, which gives conditions for the solvability of quadratic equations modulo prime numbers. There are a number of equivalent statements of the theorem, which consists of two "supplements" and the...

 (1808).
This remained the standard in mathematics until Iverson
Kenneth E. Iverson
Kenneth Eugene Iverson was a Canadian computer scientist noted for the development of the APL programming language in 1962. He was honored with the Turing Award in 1979 for his contributions to mathematical notation and programming language theory...

 introduced the names "floor" and "ceiling" and the corresponding notations and in his 1962 programming language APL.
Discussion
Ask a question about 'Floor function'
Start a new discussion about 'Floor function'
Answer questions from other users
Full Discussion Forum
 
Encyclopedia
In mathematics
Mathematics
Mathematics is the science and study of quantity, structure, space, and change. Mathematicians seek out patterns, formulate new conjectures, and establish truth by rigorous deduction from appropriately chosen axioms and definitions....

 and computer science
Computer science
Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems. It is frequently described as the systematic study of algorithmic processes that create, describe and transform...

, the floor and ceiling function
Function (mathematics)
In mathematics, a function is a relation between a given set of elements and another set of elements , which associates each element in the domain with exactly one element in the codomain...

s map a real number
Real number
In mathematics, the real numbers include both rational numbers, such as 42 and −23/129, and irrational numbers, such as pi and the square root of two; or, a real number can be given by an infinite decimal representation, such as 2.4871773339..., where the digits continue in some way; or, the real...

 to the next smallest or next largest integer
Integer
The integers are natural numbers including 0 and their negatives . They are numbers that can be written without a fractional or decimal component, and fall within the set {.....

. More precisely, floor(x) is the largest integer not greater than x and ceiling(x) is the smallest integer not less than x.

Notation


Gauss
Carl Friedrich Gauss
Johann Carl Friedrich Gauss was a German mathematician and scientist who contributed significantly to many fields, including number theory, statistics, analysis, differential geometry, geodesy, geophysics, electrostatics, astronomy and optics...

 introduced the square bracket notation [x] for the floor function in his third proof of quadratic reciprocity
Quadratic reciprocity
The law of quadratic reciprocity is a theorem from modular arithmetic, a branch of number theory, which gives conditions for the solvability of quadratic equations modulo prime numbers. There are a number of equivalent statements of the theorem, which consists of two "supplements" and the...

 (1808).
This remained the standard in mathematics until Iverson
Kenneth E. Iverson
Kenneth Eugene Iverson was a Canadian computer scientist noted for the development of the APL programming language in 1962. He was honored with the Turing Award in 1979 for his contributions to mathematical notation and programming language theory...

 introduced the names "floor" and "ceiling" and the corresponding notations and in his 1962 programming language APL. Both notations are now used in mathematics; this article follows Iverson.

The floor function is also called the greatest integer or entier (French for "integer") function, and the floor of a nonnegative x may be called the integral part or integral value of x. Computer languages (other than APL) commonly use ENTIER(x) (Algol), floor(x), or int(x) (C and C++). In mathematics, it can also be written with boldface or double brackets .

The ceiling function is usually denoted by ceil(x) or ceiling(x) in non-APL computer languages. In mathematics, there is another notation with reversed boldface or double brackets or just using normal reversed brackets ]x[.

Examples

Sample value Floor Ceiling Fractional part
−2.7 −3 −2 0.3
−2 −2 −2 0
12/5 = 2.4 2 3 2/5 = 0.4
2.7 2 3 0.7


See below for the definition of the fractional part function.

Definition and Properties


In the following formulas, x and y are real numbers, k, m, and n are integers, and is the set of integer
Integer
The integers are natural numbers including 0 and their negatives . They are numbers that can be written without a fractional or decimal component, and fall within the set {.....

s (positive, negative, and zero).

Floor and ceiling may be defined by the set equations
Since there is exactly one integer in a half-open interval of length one, for any real x there are unique integers m and n satisfying

Then   and 
 may also be taken as the definition of floor and ceiling.

As stated above,    and  

Equivalences


These formulas can be used to simplify expressions involving floors and ceilings.
In the language of order theory
Order theory
Order theory is a branch of mathematics that studies various kinds of binary relations that capture the intuitive notion of ordering, providing a framework for saying when one thing is "less than" or "precedes" another. This article gives a detailed introduction to the field and includes some of...

, the floor function is a residuated mapping
Residuated mapping
In mathematics, the concept of a residuated mapping arises in the theory of partially ordered sets. It refines the concept of a monotone function....

, that is, part of a Galois connection
Galois connection
In mathematics, especially in order theory, a Galois connection is a particular correspondence between two partially ordered sets . The same notion can also be defined on preordered sets or classes; this article presents the common case of posets. Galois connections generalize the correspondence...

: it is the upper adjoint of the function that embeds the integers into the reals.
These formulas show how adding integers to the arguments affect the functions:
The above are not necessarily true if n is not an integer; however:

Relations among the functions


It is clear from the definitions that   with equality if and only if x is an integer, i.e.

In fact, since for integers n:

Negating the argument switches floor and ceiling and changes the sign:   i.e.
Negating the argument complements the fractional part:
The floor, ceiling, and fractional part functions are idempotent
Idempotence
Idempotence describes the property of operations in mathematics and computer science that means that multiple applications of the operation do not change the result...

:
The result of nested floor or ceiling functions is the innermost function:

For fixed y, x mod y is idempotent:

Also, from the definitions,

Quotients


If n ≠ 0,

If n is positive
If m is positive
For m = 2 these imply
More generally, for positive m
The following can be used to convert floors to ceilings and vice-versa (m positive)
If m and n are positive and coprime
Coprime
In mathematics, two integers a and b are said to be coprime or relatively prime if they have no common positive factor other than 1 or, equivalently, if their greatest common divisor is 1...

, then

Since the right-hand side is symmetrical in m and n, this implies that
More generally, if m and n are positive,
This is sometimes called a reciprocity law.

Continuity


None of the functions discussed in this article are continuous
Continuous function
In mathematics, a continuous function is a function for which, intuitively, small changes in the input result in small changes in the output. Otherwise, a function is said to be discontinuous. A continuous function with a continuous inverse function is called bicontinuous...

, but all are piecewise linear.   and are piecewise constant function
Constant function
In mathematics, a constant function is a function whose values do not vary and thus are constant. For example, if we have the function f = 4, then f is constant since f maps any value to 4...

s, with discontinuites at the integers. also has discontinuites at the integers, and   as a function of x for fixed y is discontinuous at multiples of y.

  is upper semi-continuous
Semi-continuity
In mathematical analysis, semi-continuity is a property of extended real-valued functions that is weaker than continuity...

 and    and   are lower semi-continuous. x mod y is lower semicontinuous for positive y and upper semi-continuous for negative y.

Series expansions


Since none of the functions discussed in this article are continuous, none of them have a power series
Power series
In mathematics, a power series is an infinite series of the formwhere an represents the coefficient of the nth term, c is a constant, and x varies around c...

 expansion. Since floor and ceiling are not periodic, they do not have Fourier series
Fourier series
In mathematics, a Fourier series decomposes a periodic function or periodic signal into a sum of simple oscillating functions, namely sines and cosines . The study of Fourier series is a branch of Fourier analysis...

 expansions.

x mod y for fixed y has the Fourier series expansion
in particular {x} = x mod 1 is given by
At points of discontinuity, a Fourier series converges to a value that is the average of its limits on the left and the right. For x mod y, y fixed, the Fourier series converges to y/2 at multiples of y. At points of continuity the series converges to the true value.

Using the formula {x} = x − floor(x), floor(x) = x − {x} gives

Fractional part


The fractional part sawtooth function, denoted by for real x is defined by the formula

For all x,

If x is positive, the floor of x is simply x with everything to the right of the decimal point replaced with 0, and the fractional part is x with everything to the left of the decimal point replaced with 0.

mod operator


The mod operator, denoted by x mod y for real x and y, y ≠ 0, is defined by the formula
x mod y is always between 0 and y; i.e.

if y is positive,
and if y is negative,

If x is an integer and y is a positive integer,

x mod y for a fixed y is a sawtooth function.

Quadratic reciprocity


Gauss's third proof of quadratic reciprocity, as modified by Eisenstein, has two basic steps.

Let p and q be distinct positive odd prime numbers, and let

First, Gauss's lemma
Gauss's lemma (number theory)
Gauss's lemma in number theory gives a condition for an integer to be a quadratic residue. Although it is not useful computationally, it has theoretical significance, being involved in some proofs of quadratic reciprocity....

 is used to show that the Legendre symbol
Legendre symbol
The Legendre symbol or quadratic character is a function introduced by Adrien-Marie Legendre in 1798 during his partly successful attempt to prove the law of quadratic reciprocity....

s are given by
and

The second step is to use a geometric argument to show that
Combining these formulas gives quadratic reciprocity in the form
There are formulas that use floor to express the quadratic character of small numbers mod odd primes p:

Rounding


The ordinary rounding
Rounding
Rounding a numerical value means replacing it by another value that is approximately equal but has a shorter, simpler, or more explicit representation; for example, replacing US$ 23.4476 by US$ 23.45, or the fraction 312/937 by 1/3, or by 1.41....

 of the positive number x to the nearest integer can be expressed as

Number of digits


The number of digits in base b of a positive integer k is

Factors of factorials


Let n be a positive integer and p a positive prime number. The exponent of the highest power of p that divides n! is given by the formula
Note that this is a finite sum, since the floors are zero when pk > n.

Beatty sequence


Beatty sequence
Beatty sequence
A Beatty sequence is a sequence formed by successive positive integer multiples of a positive irrational number rounded down to the nearest integer, so that the sequenceIf then is also a positive irrational number. They naturally satisfy...

 shows how every positive irrational number
Irrational number
In mathematics, an irrational number is any real number that is not a rational number—that is, it is a number which cannot be expressed as a fraction m/n, where m and n are integers, with n non-zero. Informally, this means numbers that cannot be represented as simple fractions...

 gives rise to a partition of the natural number
Natural number
In mathematics, there are two conventions for the set of natural numbers: it is either the set of positive integers {, , , ...} according to the traditional definition or the set of non-negative integers {, 1, 2, ...} according to...

s into two sequences via the floor function.

Euler's constant γ


There are formulas for Euler's constant
Euler–Mascheroni constant
The Euler–Mascheroni constant is a mathematical constant recurring in analysis and number theory, usually denoted by the lowercase Greek letter ....

 γ = 0.57721 56649 ... that involve the floor and ceiling, e.g.
and

Riemann ζ function


The fractional part function also shows up in integral representations of the Riemann zeta function
Riemann zeta function
In mathematics, the Riemann zeta function, named after German mathematician Bernhard Riemann who introduced it in 1859, is a prominent function of great significance in number theory because of its relation to the distribution of prime numbers...

. It is straightforward to prove (using integration by parts) that if φ(x) is any function with a continuous derivative in the closed interval [a, b],
Letting φ(n) = n−s for real part
Real part
In mathematics, the real part of a complex number , is the first element of the ordered pair of real numbers representing , i.e. if , or equivalently, , then the real part of is . It is denoted by or , where is a capital R in the Fraktur typeface...

 of s greater than 1 and lettting a and b be integers, and letting b approach infinity gives
This formula is valid for all s with real part greater than −1, (except s = 1, where there is a pole) and combined with the Fourier expansion for {x} can be used to extend the zeta function to the entire complex plane and to prove its functional equation.

For s = σ + i t in the critical strip (i.e. 0 < σ < 1),
In 1947 van der Pol
Balthasar van der Pol
Balthasar van der Pol was a Dutch physicist.Van der Pol studied physics in Utrecht, and in 1920 he was awarded his doctorate . He studied experimental physics with John Ambrose Fleming and Sir J. J. Thomson in England...

 used this representation to construct an analogue computer for finding roots of the zeta function.

Formulas for prime numbers


n is a prime if and only if
Let r > 1 be an integer, pn be the nth prime, and define
Then
There is a number θ = 1.3064... with the property that
are all prime.

There is also a number ω = 1.9287800... with the property that
are all prime.

π(x) is the number of primes less than or equal to x. It is a straightforward deduction from Wilson's theorem
Wilson's theorem
In mathematics, Wilson's theorem states that a natural number n > 1 is a prime number if and only if.- History :...

 that
Also, if n ≥ 2,
No formula in this section is of any practical use.

Solved problem


Ramanujan submitted this problem to the Journal of the Indian Mathematical Society.

If n is a positive integer, prove that

(i)    

(ii)    

(iii)    

Unsolved problem


The study of Waring's problem
Waring's problem
In number theory, Waring's problem, proposed in 1770 by Edward Waring, asks whether for every natural number k there exists an associated positive integer s such that every natural number is the sum of at most s kth powers of natural numbers...

 has led to an unsolved problem:

Are there any positive integers k, k ≥ 6, such that
Mahler
Kurt Mahler
Kurt Mahler was a mathematician and Fellow of the Royal Society.He was a student at the universities in Frankfurt and Göttingen, graduating with a Ph.D...

 has proved there can only be a finite number of such k; none are known.

C and C++


The C
C (programming language)
C is a general-purpose computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

, C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features...

, and related programming languages (such as C#, Java) have standard functions floor and ceil.

An alternative to these functions is to convert
Type conversion
In computer science, type conversion or typecasting refers to changing an entity of one data type into another. This is done to take advantage of certain features of type hierarchies...

 floating point
Floating point
In computing, floating point describes a system for numerical representation in which a string of digits represents a rational number....

 values into integers using the type casting syntax: (int) value. The fractional part is discarded whether the value is positive or negative. (i.e., the value is truncated
Truncation
In mathematics, truncation is the term for limiting the number of digits right of the decimal point, by discarding the least significant ones.For example, consider the real numbersThe result would be:- Truncation and floor function :...

 toward zero)

Spreadsheet software


Most spreadsheet programs support some form of a ceiling function. Although the details differ between programs, most implementations support a second parameter—a multiple of which the given number is to be rounded to. As a typical example, ceiling(2, 3) would round 2 up to the nearest multiple of 3, so this would return 3. The definition of what "round up" means, however, differs from program to program.

Microsoft Excel
Microsoft Excel
Microsoft Excel is a spreadsheet-application written and distributed by Microsoft for Microsoft Windows and Mac OS X. It features calculation, graphing tools, pivot tables and a macro programming language called VBA...

's ceiling function does not follow the mathematical definition, but rather as with (int) operator in C, it is a mixture of the floor and ceiling function: for x ≥ 0 it returns ceiling(x), and for x < 0 it returns floor(x). This has followed through to the Office Open XML file format. For example, CEILING(-4.5) returns −5. A mathematical ceiling function can be emulated in Excel by using the formula "-INT(-value)" (please note that this is not a general rule, as it depends on Excel's INT function, which behaves differently than most programming languages).

The OpenDocument
OpenDocument
The OpenDocument Format is an XML-based file format for representing electronic documents such as spreadsheets, charts, presentations and word processing documents....

 file format, as used by OpenOffice.org
OpenOffice.org
OpenOffice.org , commonly known as OpenOffice, is an office application suite available for a number of different computer operating systems. It is distributed as free software and written using its own GUI toolkit...

 and others, follows the mathematical definition of ceiling for its ceiling function, with an optional parameter for Excel compatibility. For example, CEILING(-4.5) returns −4.

Typesetting


The floor and ceiling function are usually typeset with left and right square brackets where the upper (for floor function) or lower (for ceiling function) horizontal bars are missing, and, e.g., in the LaTeX
LaTeX
LaTeX is a document markup language and document preparation system for the TeX typesetting program. Within the typesetting system, its name is styled as ....

 typesetting system these symbols can be specified with the \lfloor, \rfloor, \lceil and \rceil commands in math mode. Unicode
Unicode
Unicode is a computing industry standard allowing computers to consistently represent and manipulate text expressed in most of the world's writing systems...

 contains codepoints for these symbols, at U+2308U+230B: ⌈x⌉, ⌊x⌋.

See also

  • Nearest integer function
    Nearest integer function
    In mathematics, the nearest integer function of real number x denoted variously by , , , nint, or Round, is a function which returns the nearest integer to x...

  • Truncation
    Truncation
    In mathematics, truncation is the term for limiting the number of digits right of the decimal point, by discarding the least significant ones.For example, consider the real numbersThe result would be:- Truncation and floor function :...

    , a similar function
  • Step function
    Step function
    In mathematics, a function on the real numbers is called a step function if it can be written as a finite linear combination of indicator functions of intervals...


External links

  • Štefan Porubský, "Integer rounding functions", Interactive Information Portal for Algorithmic Mathematics, Institute of Computer Science of the Czech Academy of Sciences, Prague, Czech Republic, retrieved 10/24/2008