- Floor and ceiling functions
In
mathematics andcomputer science , the floor and ceiling functions mapreal number s to nearbyinteger s. [Ronald Graham ,Donald Knuth andOren Patashnik . "Concrete Mathematics". Addison-Wesley, 1999. Chapter 3, "Integer Functions".]The floor function, sometimes called the greatest integer function, of a real number "x", denoted variously by [,cite book | author=J.W.S. Cassels | title=An introduction to Diophantine approximation | series=Cambridge Tracts in Mathematics and Mathematical Physics | volume=45 | publisher=
Cambridge University Press | year=1957 | pages=1] , floor("x"), or int("x") [Michael Sullivan. "Precalculus", 8th edition, p. 86] [ [http://mathworld.wolfram.com/FloorFunction.html Floor Function — from Wolfram MathWorld] ] , is a function whose value is the largest integer less than or equal to "x". Formally, for all real numbers "x",:
For example, floor(2.9) = 2, floor(−2) = −2 and floor(−12/5) = −3. For
nonnegative "x", a more traditional name for floor("x") is the integral part or integral value of "x". The function , also written as "x" mod 1, or {"x"}, is called the fractional part of "x". Every fraction "x" can be written as amixed number , the sum of an integer and aproper fraction . The floor function and fractional part functions extend this decomposition to all real values.The closely-related ceiling function, denoted or ceil("x") or ceiling("x"), is the function whose value is the smallest integer not less than "x", or, formally,
:
For example, ceiling(2.3) = 3, ceiling(2) = 2 and ceiling(−12/5) = −2.
The names "floor" and "ceiling" and the corresponding notations were introduced by
Kenneth E. Iverson in 1962. [Nicholas J. Higham, "Handbook of writing for the mathematical sciences", SIAM. ISBN 0898714206, p. 25] [Kenneth E. Iverson. "A Programming Language". Wiley, 1962.]Some properties of the floor function
* For all "x",:::with equality on the left if and only if "x" is an integer.
* The floor function is idempotent: .
* For any integer "k" and any real number "x",:
*The ordinaryrounding of the positive number "x" to the nearest integer can be expressed as floor("x" + 0.5).
* The floor function is not continuous, but it is upper semi-continuous. Being a piecewiseconstant function , itsderivative is zero where it exists, that is, at all points which are not integers.
* If "x" is a real number and "n" is an integer, one has "n" ≤ "x"if and only if "n" ≤ floor("x"). In the language oforder theory , the floor function is aresiduated mapping , that is, part of aGalois connection : it is the upper adjoint of the function that embeds the integers into the reals.
* If "x" is a real number and "n" is an integer, holds.
* Using the floor function, one can produce several explicit (yet impractical) formulas for prime numbers.
* For real, non-integer "x", the floor function has theFourier series representation:
* If "m" and "n" arecoprime positive integers, then :
*Beatty's theorem shows how every positiveirrational number gives rise to a partition of thenatural number s into two sequences via the floor function.
* The number of digits in base "b" of a positive integer "k" is:Some properties of the ceiling function
* It is easy to show that::
* Also::
* For any integer "k", we have the following equality:: .Some properties of the fractional part function
* For all "x":::with equality on the left if and only if "x" is an integer.
* For positive integers "m", "n"::
Computer implementations
The operator
(int)
in CC and related
programming language s convertfloating point values into integers using the type casting syntax:(int) value
. The fractional part is discarded (i.e., the value is truncated toward zero) [ISO/IEC. "ISO/IEC 9899::1999(E): Programming languages — C" (2nd ed), 1999; Section 6.3.1.4, p. 43.] .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 'sceiling
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 theOffice 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'sINT
function, which behaves differently that most programming languages).The
OpenDocument file format, as used byOpenOffice.org and others, follows the mathematical definition of ceiling for itsceiling
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 typesetting system these symbols can be specified with the lfloor, floor, lceil and ceil commands in math mode.Unicode containscodepoint s for these symbols, atU+2308
–U+230B
: ⌈"x"⌉, ⌊"x"⌋.See also
*
Nearest integer function
*Truncation , a similar functionNotes
Wikimedia Foundation. 2010.