In mathematics, the floor function for a real number x, floor(x) also denoted by is the function defined as . This is, the largest integer less than or equal to 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 , 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.
A closely related mathematical function is the ceiling function, given x, ceiling(x) also denoted by is the function defined as . This is, the smallest integer not less than x. For example, ceiling(2.3) = 3, ceiling(2) = 2 and ceiling(−2.3) = −2.
(int) in C
C and related programming languages have a feature called type casting which allows to turn a floating point 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).
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 happily convert to 2.
Many other languages, such as Java (tested with Sun JDK version 1.5.0_05) and Perl (as of version 5.8.0) behave similarly, as does the POSIX floor() function.
Because of issues like these, most modern calculators use the decimal numeral system internally.
If x is an irrational number, then the fractional parts nx mod 1, where n runs through the positive integers, are uniformly distributed in the open interval (0,1). This can be made precise in various ways, one of which states
According to a general principle of diophantine approximation discovered by Hermann Weyl, that property is equivalent to something much easier to check in this case: namely that sums
for have estimates O(N). Because these are geometric progressions, that can be proved rather directly. The condition that x be irrational comes out to be that
Функция скобка | Gaußklammer | Función parte entera | Partie entière | 床関数 | Entierfunctie | Część całkowita | целая часть | celi del
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Floor function".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world