Re: Float comparison
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 15 May 2009 19:36:50 -0700
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"
.
- References:
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: Keith Thompson
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: crisgoogle
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- From: crisgoogle
- Re: Float comparison
- From: CBFalconer
- Re: Float comparison
- Prev by Date: Re: Float comparison
- Next by Date: Re: Microsoft and memcpy?
- Previous by thread: Re: Float comparison
- Next by thread: Re: Float comparison
- Index(es):
Relevant Pages
|