[Slightly OT]: More on ints and floats

Lulu of the Lotus-Eaters mertz at gnosis.cx
Tue Apr 8 04:07:57 CEST 2003


Tim Daneliuk <tundra at tundraware.com> wrote previously:
|As I understand it, integers and floats are distinct mathematical
|entities. A colleague of mine claims, that insfar as we use them in
|computing, ints are merely a proper subset of floats.

Floats are peculiar creatures.  They really are not much like Real or
Rational numbers, even though it is often convenient to pretend they
are.  The trick about floating point numbers is that although they are
extremely useful for representing real-life (fractional) quantities,
operations on them do not obey the arithmetic rules we learned in middle
school:  associativity, transitivity, commutativity; moreover, many very
ordinary-seeming numbers can be represented only approximately with
floating point numbers.  For example:

     >>> 1./3
     0.33333333333333331
     >>> .3
     0.29999999999999999
     >>> 7 == 7./25 * 25
     0
     >>> 7 == 7./24 * 24
     1

Tim knows this, of course, but it is worth emphasizing.  Moreover, a
quote the Timbot found for this list a couple years ago is worth
reiterating:

  Many serious mathematicians have attempted to analyze a
  sequence of floating point operations rigorously, but found
  the task so formidable that they have tried to be content
  with plausibility arguments instead.
  -- Donald Knuth (_The Art of Computer Programming_, Third Edition,
     Addison-Wesley, 1997; ISBN:  0201896842, vol.  2, p.  229):

Yours, Lulu...

--
Keeping medicines from the bloodstreams of the sick; food from the bellies
of the hungry; books from the hands of the uneducated; technology from the
underdeveloped; and putting advocates of freedom in prisons.  Intellectual
property is to the 21st century what the slave trade was to the 16th.





More information about the Python-list mailing list