ebooksgratis.com

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
Floor and ceiling functions - Wikipedia, the free encyclopedia

Floor and ceiling functions

From Wikipedia, the free encyclopedia

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

In mathematics and computer science, the floor and ceiling functions are two mathematical functions which convert arbitrary real numbers to close integers.[1]

The floor function of a real number x, denoted \lfloor x \rfloor or floor(x), is a function that returns the highest 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(−2.3) = −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 that returns the smallest integer not less than x, or, formally,

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

For example, ceiling(2.3) = 3, ceiling(2) = 2 and ceiling(−2.3) = −2.

The names "floor" and "ceiling" and the corresponding notations were introduced by Kenneth E. Iverson in 1962.[2]

Contents

[edit] Some properties of the floor function

  • One has
 \lfloor x\rfloor \le x < \lfloor x \rfloor + 1
with equality on the left if and only if x is an integer.
  • When x and n are positive numbers
 \left\lfloor \frac{n}{x} \right\rfloor \geq \frac{n}{x} - \frac{x-1}{x}
  • 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.
  • The ordinary rounding of the 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 piecewise constant function, its derivative 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 nx if and only if n ≤ floor(x). In fancy language: the floor function is part of a Galois connection; it is the upper adjoint of the function that embeds the integers into the reals.
  • Using the floor function, one can produce several explicit (yet impractical) formulas for prime numbers.
  • For real, non-integer x, the floor function has the Fourier series representation
\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_{10}(k) \rfloor + 1

[edit] 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.

[edit] The operator (int) in C

The (int) function
The (int) function

C and related programming languages have a feature called type casting which allows turning a floating point value into an integer by prefixing it with (int). This operation is truncation or the round to zero method, a mixture of the floor and ceiling function: for positive or 0 x it returns floor(x), and for negative x it returns ceiling(x).

This operation loses significant data, and can therefore magnify rounding errors with disastrous consequences. For instance, (int)(0.6/0.2) will return 2 in most implementations of C, even though 0.6/0.2 = 3. The reason is that computers work internally with the binary numeral system, and it is not possible to represent the numbers 0.6 and 0.2 by a finite binary string. So some rounding errors occur, and the result is computed as 2.999999999999999555910790149937 which the (int) operator will convert to 2.

Many other languages, such as Java (tested with Sun JDK version 1.5.0_05), Perl (as of version 5.8.0), and PHP (tested on version 5.2.1) behave similarly and exhibit rounding errors, as does the POSIX floor() function, every time floating point types are used to store real values.[original research?]

Because of issues like these, most modern calculators use the decimal numeral system internally, but this only solves a small part of possible problems, and not the fact that (int)((4.0/9.0) * 9.0) will still return 3 instead of 4, even when using decimal floating point representation at any datatype precision (The effective result comes from the truncation of 0.44444...4444 * 9.0 = 3.99999...9996, for which either a binary or decimal internal base has no influence on the precision of the result and the error, even when correct rounding to the nearest representable number is used throughout the calculation).

A workaround is to define an epsilon constant e (e.g. e = 0.00000001), and define floor(x) = (int)(x + e), and ceiling(x) = (int)(x + e) + 1, for x >= 0,

A more elegant solution is to use better numeric datatypes to allow representing rational values exactly, or to avoid aggravating rounding errors which will only appear when non polynomial functions are used in the calculation. For example, a pair can be used for storing a floating point numerator and a positive integer divisor (a solution used in the Calculator accessory in Windows): all intermediate calculation and storage use this datatype, and the decimal floating point value is computed only for the final display of the calculator, with correct rounding up to the displayed precision.

[edit] Computer implementations

Practically every spreadsheet program supports 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 \geq 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.

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.

Mathematica also follows the mathematical definition.

[edit] Truncation

While the floor function only outputs integers, the act of real truncation, or "cutting off the digits", may be performed at any specified position, not necessarily after the units digit.

[edit] 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⌋.

[edit] Notes

  1. ^ Ronald Graham, Donald Knuth and Oren Patashnik. "Concrete Mathematics". Addison-Wesley, 1999. Chapter 3, "Integer Functions".
  2. ^ Kenneth E. Iverson. "A Programming Language". Wiley, 1962.


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -