Re: Float comparison



CBFalconer <cbfalconer@xxxxxxxxx> writes:
crisgoogle@xxxxxxxxx wrote:
CBFalconer <cbfalco...@xxxxxxxxx> wrote:
... snip ...

No, because the arithmetic system on unsigned ints is closed.
Apart from division by zero, you can't generate a value outside
the set 0 .. UINT_MAX. Those things are not integers. They
follow defined rules. They are not intended to represent
integers. Similarly floats are not reals, and also follow
defined rules. However we can always deposit a real in a float,
and the question is 'what is that real'.

Right, the floats follow defined rules, and under those rules,
they _are_ closed. Operations on floats result in floats. As
someone else (Keith T?) mentioned elsthread, any real value that
might, theoretically, be the mathematical result of any float
operation _never_ exists in the computer. The operands are floats,
the FPU stores them and the results in floating point registers,
and the value stored back to memory is a float.

This is a quickie, but floats are NOT closed. Reals are closed.
For most implementations floats have specific changes each time the
value is doubled (or halved). If you form:

c = a + b;
d = c - a;

and examine b and d, they will normally be different.
Precondition: a is greater than 2 * b, or b is greater than 2 * a.

That's not what "closed" means. A set is closed under an operation if
applying that operation to members of the set always yields a member
of the set. It's not about reversibility.

Whether the set of floats is closed under addition is
implementation-specific. The behavior on overflow (or division by
zero) is undefined. If addition of two floats always yields either a
numeric float value, a NaN, or an infinity, then the set of floats is
closed under addition. If some addition operators can cause the
program to crash rather than yielding a result, then it isn't.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: How about adding rational fraction to Python?
    ... This behavior is what is intended in numeric type unification, floats ... float is inexact and reals is impossible, and thus epsilon comparison ...
    (comp.lang.python)
  • Re: Function terminology
    ... > semantics, but the relationship between code and math is still so ... And one with much hairier properties. ... > exactly for the same reason that we shouldn't call floats with the same ... are representations of reals, and if you're talking about a program's ...
    (comp.lang.lisp)
  • Re: Float comparison
    ... snip ... ... Apart from division by zero, you can't generate a value outside ... Right, the floats follow defined rules, and under those rules, ... Reals are closed. ...
    (comp.lang.c)
  • Re: C2124 is most disrespectful of IEEE floating point arithmetic
    ... There is not one single "mathematics". ... division behave differently with integers as compared to reals). ... unlike floats which are not. ... It's not a flag from the compiler but from the C++ library. ...
    (microsoft.public.vc.language)
  • Re: Why does everyone do it?
    ... But what has _this_ to do with the uncountability of the reals? ... a digital computer, I see integers, and floats, nothing power set alike. ... There's nothing infinite inside your computer, ... Why in the world should mathematics be restricted to what ...
    (sci.math)