[Slightly OT]: More on ints and floats

Steve Holden sholden at holdenweb.com
Mon Apr 7 21:03:25 EDT 2003


"Tim Daneliuk" <tundra at tundraware.com> wrote in message
news:fjss6b.1021.ln at boundary.tundraware.com...
> OK, I don't want to resurrect another interminable discourse in ints,
> floats, and how they are/ought/can be handled in the language. But, I
> have a sort of theoretical mathematical question which the whole
> business brought to mind.
>
> 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. He furthermore
> asserts that (again as regards to computing) the distinction between
> them was made as a purely as a practical matter because floating point
> arithmetic was historically computationally expensive. He argues that
> any place one can use an int, these days (with cheap FP hardware), one
> could use a float 0 extended to the precision of the machine and get
> equivalent computational results. Say the hardware supported 4 digits of
> precision. He is arguing that:
>
>
>     3/4.0000  is equivalent to 3.0000/4.0000
>
> (Never mind the old Python modulo vs. divison debate.)
>
> In effect he is saying that, unless there is a practical
> performance/cost issue at hand, there is no real reason to
> differentiate between ints and floats in practical programming
> problems.
>
Well, that depends on how each is represented. Suppose you had a platform
with 64-bit integers and 64-bit floats. It would be impossible to represent
every integer as a floating-point number because the mantissa in the floats
will be shorter than the integer precision.

Of course, now we are moving towards infinite-precision integers (with
hidden widening to long when required) this problem will always exist.

> As a matter of 'pure' mathematics, I argued that ints and floats are
> very different critters. My argument (which is no doubt formally very
> weak) is that the integer 3 and the float 3.0000 are different because
> of the precision problem.  For instance, the integer 3 exists at a single
> invariant point on the number line, but 3.0000 represents all numbers
> from 2.99995 through 3.00004.
>
As a matter of pure mathematics the integers are a subset of the reals,
which are a subset of the complex numbers.

Unfortunately pure mathematics and floating-point arithmetic only tend to
intersect in the brains of people like Tim Peters.

> Could one of the genius mathematicians here bring some clarity to this
> discussion, please?
>
So I guiess it's the timbot you want to hear from then, and not me :-)

regards
--
Steve Holden                                  http://www.holdenweb.com/
Python Web Programming                 http://pydish.holdenweb.com/pwp/
Did you miss PyCon DC 2003?            Would you come to PyCOn DC 2004?







More information about the Python-list mailing list