Array indexing vs. pointers...

Rob Carriere rob at kaa.eng.ohio-state.edu
Sun Oct 9 10:52:25 AEST 1988


In article <8273 at alice.UUCP> ark at alice.UUCP (Andrew Koenig) writes:
>In particular, when
>I convert 100 degrees Celsius to Fahrenheit [using * and /], I get 212, not
>211.9999999999999 or 212.0000000000001.  The other two ways of
>doing it do not guarantee that.

Probably.  However, as thermometers more accurate than about +-.1K are
fairly rare, what's the diff?  You can't rely on the number being more
precise than about +-.05 degrees F anyway, due to the inaccuracy of
your input.  This is exactly the point the original poster was trying
to make; if *you* know the last couple of bits don't matter, you might
as well take advantage of that fact.  If on the other hand, this
measurement was made using a Star Trek tricorder (which is accurate to
12 decimal places) and had to be reported to Spock, *then* you'd
better be careful that you don't destroy any bits of accuracy, and use
your trick (and double precision).

Rob Carriere



More information about the Comp.lang.c mailing list