Re: Float comparison



On Wed, 29 Apr 2009 00:01:47 -0400, CBFalconer <cbfalconer@xxxxxxxxx>
wrote:

Flash Gordon wrote:

... snip ...

You have also completely ignored the fact that I have presented
situations where the integer types *are* used as approximations.

So, is int just an approximation?

No, although it may be so used. It is intended to handle integers,
and, except for division, the set of integers is closed under
elementary arithmetic. People are quite familiar with the idea
that a division results in a quotient and a remainder, under which
condition the integer set remains closed.

So are the reals with the same exception.

But the bounded computer/C types int, long etc. aren't closed for
addition/subtraction and multiplication. (And with usual 2sC not quite
for negation.) The C unsigned integer types are closed (except
zerodiv) only because they implement Z sub N rather than Z.

You can't make these statements about FP values.

Computer (non-bignum*) integers are not the mathematical ones any more
than computer floats are mathematical reals. Although it seems in
practice programmers are more often able to cope with the deficiences
of almost-integers better than they do with almost-reals.

* Technically bignums aren't perfect either, but they're good enough
that they only break when you try to break them, whereas 32-bit and
64-bit break in some real programs if you're just a little careless.
We (at least I) don't have enough experience yet with 128 to see if it
is reliably big enough, but I'm not betting the farm on it today.

.



Relevant Pages

  • Re: Moving from 8051 to AVR
    ... bit integer types of signed and unsigned char. ... The reason is that on 8 bit machines a 16 bit int requires 2 fetches ... Also if the items being operated on are 8 bit integer types ... instructed to turn off the integer promotion. ...
    (comp.arch.embedded)
  • Re: Difficulty of passing char[] to function accepting unsigned char*
    ... representation of integer types - ... A valid object representation of a signed integer type ... anticipated non-contiguous ranges then different language would have ... No for any signed type no bigger than int. ...
    (comp.lang.c)
  • Re: Question for a REAL expert on casting double to float...
    ... the big difference between integer types and float types? ... It's not a case of integer types behaving differently from floating ... If you'd been using an ILP64 (43 bit int, 64 bit long) system you would ... help from the compiler in diagnosing any errors. ...
    (comp.lang.c)
  • Re: unsigned short addition/subtraction overflow
    ... short _are_ representable as an int. ... operands, ... A cast will not _override_ integral promotion. ... implementing unsigned integer types as a whole, ...
    (comp.lang.c)
  • Re: NULL and zeros
    ... that's going to result in object set ... and that is required to mean "value 0" for integer types. ... to suggest it was a quote from the Standard, but I apologise if anyone was ... int crossfade(unsigned long ximages, ...
    (comp.lang.c)