floor() function definition

Dennis E. Hamilton orcmid at email.com
Wed May 16 00:15:58 EDT 2001


I apologize for the flak your simple question attracted.  Here's what passes
for me as a straight answer:

	floor(x) is defined to be the greatest integer that is not larger than x.

The function is not all that well-known, and if I stood in the hallway of a
mathematics department, I could doubtless find people unable to define it
correctly.  You had one respondee who defined it incorrectly, in fact.

The definition takes getting a little accustomed to.  One key feature is
that floor(floor(x)) = floor(x), and if x is already an integer, floor(x) =
x.

As you might surmise, the ceiling function, ceil(x) is defined to be the
smallest integer not less than x.

One way to think of this is that ceil(abs(x)) is the number of unit-sized
boxes it takes to pack quantity abs(x) of something, and floor(abs(x)) is
the number of unit-sized boxes that can be packed into a size abs(x)
"space."

Until around 1960, these functions were not widely known.  The notation for
them was introduced by Kenneth Iverson in APL and Donald Knuth gave them
solid treatment in The Art of Computer Programming.  At least, those are the
places where I first saw them.  There are many useful identities using these
functions and they are particularly valuable in expressing the integral part
of a quotient in the form that matters for a problem.  I have an example of
that in discussion of a Python version of the usual Binary Search algorithm,
at


http://www.infonuovo.com/orcmid/readings/R010101.htm#BinarySearchImplementat
ion

and I use floor explicitly in expressing the algorithm.

One fascinating identify for these functions is that

	ceil(x) = -floor(-x)

and, of course, vice versa.

The Python real-number versions of these functions are very interesting for
a way they can fail.  When x is too large in magnitude to be an exact
integer, the result is an approximation in precisely the same way.  There's
not much that can be done about that, but it is odd.  I find myself
uncomfortable about it, because there are key mathematical identities that
fail at the boundary when x becomes too large in magnitude to be safely
considered to be an integer.  That is, abs(x)+1 is abs(x), abs(x)-1 might or
might not be abs(x).   In practical applications of floor(x) and ceil(x), I
don't think this becomes a concern, though.  Just the same, my inclination
would be to raise an exception once floor(x) and ceil(x) can't be delivered
as precise integers.

I've probably given you more than you wanted to know, so I'll stop with this
much.

-- Dennis

Dennis E. Hamilton
AIIM DMware Technical Coordinator
------------------
mailto:orcmid at email.com         tel. +1-425-793-0283
http://www.dmware.org           fax. +1-425-430-8189
     ODMA Support http://www.infonuovo.com/odma


-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Dev_NuLL
Sent: Tuesday, May 15, 2001 16:36
To: python-list at python.org
Subject: floor() function definition


What does floor() do?

This is all I get from the python web site:

floor (x)
Return the floor of x as a real.

Doesn't help much if you don't know what floor means!
--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list