Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Floor function


 


In mathematics, the floor function is the function defined as follows: for a real number x, floor(x) is the largest integer less than or equal to x. For example, floor(2.9) = 2, floor(-2) = -2 and floor(-2.3) = -3. The floor function is also denoted by [x] or . A more traditional name for it is the integral part of x. The function x−[x], also written as x  mod 1, is called the fractional part of x. Every fraction x ≥ 0 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.

1 Some properties of the floor function

We always have

with equality on the left if and only if x is an integer. For any integer k and any real number x, we have

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.

If x is a real number and n is an integer, we have 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 which embeds the integers into the reals.

Using the floor function, one can produce several explicit (yet impractical) formulas for prime numbers. See the article on prime numbers for a number of examples.

2 The ceiling function

A closely related mathematical function is the ceiling function, which is defined as follows: for any given real number x, ceiling(x) is the smallest integer no less than x. For example, ceiling(2.3) = 3, ceiling(2) = 2 and ceiling(-2.3) = -2. The ceiling function is also denoted by . It is easy to show the following:

and the following:

For any integer k, we also have the following equality:

.

If m and n are coprime positive integers, then

Beatty's theoremTheorems In mathematics, Beatty's theorem states that if p and q are two positive irrational numbers with : then the positive integers : are all pairwise distinct, and each positive integer occurs precisely once in the list. Here denotes the floor functio shows how every positive irrational numberIn mathematics, an irrational number is any real number that is not a rational number, i. one that cannot be written as a fraction a ''b with a and b integers, and b not zero. It can readily be shown that the irrational numbers are precisely those numbers gives rise to a partition of the natural numberNatural number can mean either a positive integer ( 1, 2, 3, 4,. or a non-negative integer ( 0, 1, 2, 3, 4,. Natural numbers have two main purposes: they can be used for counting ("there are 3 apples on the table"), or they can be used for ordering ("thiss into two sequences via the floor function.

3 The operator (int) in C

CThe C Programming Language Brian Kernighan and Dennis Ritchie, the original edition that served for many years as an informal specification of the language The C programming language is a low-level standardized programming language developed in the early and related programming languageAn alternate rewrite has been has been. Please refer to it for large rewrites. A programming language or computer language is a standardized communication technique for expressing instructions to a computer. It is a set of syntactic and semantic rules uses have a feature called type casting which allows to turn a floating pointComputer arithmetic A floating-point number is a digital representation for a number in a certain subset of the rational numbers, and is often used to approximate an arbitrary real number on a computer. In particular, it represents an integer or fixed-poi value into an integer by prefixing it with (int). This operation is 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).

Like the floor and ceiling function, this operation is not continuous, which can 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 systemThe binary or base-two numeral system is a system for representing numbers in which a radix of two is used; that is, each digit in a binary numeral may have either of two different values. Typically, the symbols 0 and 1 are used to represent binary number, 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 happily convert to 2. The POSIX floor() function has similar problems. Because of issues like these, most modern calculators use the decimal numeral system internally.



Read more »

Non User