CBFalconer said:
Keith Thompson wrote:
.... snip ...
Oh, it exists, but not in that floating representation.
The program when running does not work with "real vaus" and then round
them to floating point representations. It works with floating point
representations only. So the "real value" never exists in the computer.
And that
is how programs accumulate relatively large 'rounding errors'.
Keith has already mentioned the need to do an error analysis if you want
to know what the possible error.
You
have to keep track of what is going on.
Earlier you said that you know what the range is *without* examining the
code. Which is it?
Watching every little
detail is excessive, and will not be done.
Wrong. Some people spend a long time doing exactly that because it is
very important and they are being paid to do it. It is called "Error
Analysis" and gets taught in universities. I've done done an approximate
error analysis on software that used integer arithmetic (for speed) in
the past, and in that program the integers where all storing approximate
values (altitude in units of 4 feet, the roll and pitch of an aircraft etc).
Always remembering that
a floating point value represents a known range is very helpful.
Apart from the fact that this is NOT true. You need to analyse th
program to know whether it is
I know of code which carefully uses doubles to do integer arithmetic,
staying within the range where integers can be represented exactly, in
order to use the greater range of exact integral values that a double
can represent on that specific implementation than an int. In this case
the stored doubles always have an exact number of pennies in them (well,
it also uses exact numbers of other things).
Now you have a description of real software in which floating point
variables always have exact values stored in them. I'm sure that over
the years I've seen other people mention similar things.
Everything you are saying applies to integer arithmetic in C as well,
because people DO use integers to hold approximate values (unless you
think planes fly at exact multiples of 4 feet and do things like jumping
from 80 feet to 84 feet without ever going through the intervening
altitudes).
So either integer types cannot store exact values and you need to do a
full error analysis to determine the range of values they might
represent or floating point variables can store exact values which are
exactly the mathematically correct values the program is intended to store.