Floor function
This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Floor_function"
.

The floor function
The floor function
The ceiling function
The ceiling function

In mathematics and computer science, the floor and ceiling functions map real numbers to nearby integers.[1]

The floor function, sometimes called the greatest integer function, of a real number x, denoted variously by x[2] \lfloor x \rfloor, floor(x), or int(x)[3][4], is a function whose value is the largest integer less than or equal to x. Formally, for all real numbers x,

 \lfloor x \rfloor=\max\, \{n\in\mathbb{Z}\mid n\le 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 x -\lfloor x\rfloor, also written as x mod 1, or {x}, is called the fractional part of x. Every fraction x can be written as a mixed number, the sum of an integer and a proper fraction. The floor function and fractional part functions extend this decomposition to all real values.

The closely-related ceiling function, denoted \lceil x \rceil or ceil(x) or ceiling(x), is the function whose value is the smallest integer not less than x, or, formally,

 \lceil x \rceil=\min\,\{n\in\mathbb{Z}\mid n\ge x\}.

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.[5][6]

content

Contents

Some properties of the floor function

  • For all x,
 \lfloor x\rfloor \le x < \lfloor x \rfloor + 1
with equality on the left if and only if x is an integer.
  • The floor function is idempotent: \lfloor\lfloor x\rfloor\rfloor=\lfloor x\rfloor.
  • For any integer k and any real number x,
 \lfloor {k+x} \rfloor = k + \lfloor x\rfloor.
\lfloor x\rfloor = x - \frac{1}{2} + \frac{1}{\pi} \sum_{k=1}^\infty \frac{\sin(2 \pi k x)}{k}.
  • If m and n are coprime positive integers, then
\sum_{i=1}^{n-1} \lfloor im / n \rfloor = (m - 1) (n - 1) / 2
\lfloor \log_{b}{k} \rfloor + 1

Some properties of the ceiling function

  • It is easy to show that:
\lceil x \rceil = - \lfloor - x \rfloor
  • Also:
x \leq \lceil x \rceil < x + 1
  • For any integer k, we have the following equality:
\lfloor k / 2 \rfloor + \lceil k / 2 \rceil = k.

Some properties of the fractional part function

  • For all x
 0 \le \{x\} < 1
with equality on the left if and only if x is an integer.
  • For positive integers m, n
0 \le \{\frac{m}{n}\} \le \frac{n-1}{n}

Computer implementations

The operator (int) in C

C and related programming languages convert floating point values into integers using the type casting syntax: (int) value. ANSI C does not define the exact semantics[7]; most implementations truncate.

Further information: Floating point

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'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 that most programming languages).

The OpenDocument file format, as used by OpenOffice.org 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 typesetting system these symbols can be specified with the \lfloor, \rfloor, \lceil and \rceil commands in math mode. Unicode contains codepoints for these symbols, at U+2308U+230B: ⌈x⌉, ⌊x⌋.

See also

Notes

  1. ^ Ronald Graham, Donald Knuth and Oren Patashnik. "Concrete Mathematics". Addison-Wesley, 1999. Chapter 3, "Integer Functions".
  2. ^ ,J.W.S. Cassels (1957). An introduction to Diophantine approximation, Cambridge Tracts in Mathematics and Mathematical Physics 45. Cambridge University Press, 1. 
  3. ^ Michael Sullivan. Precalculus, 8th edition, p. 86
  4. ^ Floor Function — from Wolfram MathWorld
  5. ^ Nicholas J. Higham, Handbook of writing for the mathematical sciences, SIAM. ISBN 0898714206, p. 25
  6. ^ Kenneth E. Iverson. "A Programming Language". Wiley, 1962.
  7. ^ Brian Kernighan, Dennis Ritchie. The C Programming Language (2nd ed), Prentice Hall 1988; ISBN 0-13-110362-8. Pp.45,197.
© jGames.co.uk 2007 (some content from Wikipedia under GDL ) !-- ValueClick Media 468x60 and 728x90 Banner CODE for jgames.co.uk -->
Your Ad Here