Re: This calculation is just wrong / computer can't count!

Tech-Archive recommends: Speed Up your PC by fixing your registry



A nice summary of the problem. Yes, I have the same problems about anyone who starts down
the path about floating point inaccuracy, but most of them can actually be educated about
it.

He made the mistake of challenging me about not asking his original question, so I went
back and re-read it, and came up with the same observation you did: he asked us to explain
why there was a difference. Once we had explained it, he told us our explanations about
reality were irrelevant, and only his opinion of a correct answer mattered. He continues
to insist that his question matters. You might look for the post where I tell him his
question is unanswerable, and he can ask it as often as he likes, and until he realizes it
is the wrong question, he won't get the answer he wants.
joe

On Thu, 11 Oct 2007 10:25:34 +0100, "Les" <l.neilson@xxxxxxxxxxxxxxxxxxx> wrote:


"Alexander Grigoriev" <alegr@xxxxxxxxxxxxx> wrote in message
news:uIaTCo6CIHA.4476@xxxxxxxxxxxxxxxxxxxxxxx
If 5 decimal fraction positions are OK for your task, do the following:

a = floor(a * 100000 + 0.5) / 100000 +5e-6;

Then you won't get -0.00000


But in another post GT says that his application considers -0.0 to be
significant.
"This looks very untidy and mathematically means something else to our
application!"

So there are conditions under which -0.0 is a required (?) meaningful (?)
result.

Therefore specific programming is required to cater for this.
_That_ programming will involve tolerances and careful comparison of
intermediate floating point values
The implication from GT's posts is that the algorithm is sensitive to the
very last bit (for the 0.83(3) number) :
1*2**-52 binary or
+4/-7 *10**-17 decimal


Note we have tried to answer his questions.
The very first question asked us to shed light on why the number he got was
not what was expected.
The reason is the limitations of IEE floating point arithmetic, granularity,
resolution error, LSB rounding etc.

Answers to further questions what to do about it included :
Reconsider the algorithm and use programming techniques with tolerances (eg
as I mention above and in another post)
or use rational number libraries
or use symbolic/algebraic math libraries

I am not familiar with either of the last two, never having had to use them.


I think we have all assumed that GT is a trained programmer.
This assumption may not be accurate.
GT may be a manager/engineer/user/accountant who has been asked to do
programming on this system.
In which case we can make allowances.

If the assumption is TRUE however then _that_ together with

(a) the subject title which contains no smiley;

(b) the question why can't the computer ignore the "7" and work to the
maximum number of 3's it can handle; This question alone set alarm bells
ringing.

(c) the flawed logical expression and deductive reasoning of his posts.
For (b) above the only way the "7" can be ignored is to make it 0, why?
because ALL bits in a variable take part in a mathematical operation
(set aside for the moment that such a decimal number is still not available
in binary)
By analogy ALL numbers in the 17 decimal places take part in the math so 7
must become 0 in order for it to be ignored.
He then accused ME of having introduced the erroneous "0"

(d) the acceptance of the photograph analogy without questioning tolerance
is RGB[0,0,0] the *only* acceptable "black"?
what about RGB[1,1,1] ?
what tolerance is GT prepared to accept before black becomes grey or any
other colour?
If the tolerance is zero then can the instruments
(paper,printer,camera,developer,scanner etc) work to that tolerance?

(e) the belief that (a/b)*c = a when c approximately = b
assuming b and c are derived from different routes through the math
and therefore the compiler can't optimise them away.

(f) the dismissal of IEE arithmetic as "wrong" and hence those who use it
are also wrong.
(More alarm bells)
Note GT also grabbed at "guard bits" as being a possible solution to the
problem. These of course are discussed in the Goldberg paper, and are part
of the IEE standard for hardware to help with catering for this very
problem.

all of these, and more, display a lack of understanding by GT of what we
have been trying to explain to him.

What conclusion can I draw from this ? GT is NOT a trained programmer ?

If GT really does believe that the way math is done in PCs using IEE
floating point arithmetic, and hence by us programmers, is wrong /
inaccurate then I think we should, as a start, abandon travelling by plane
(designed, built, navigated and controlled by computers using this
arithmetic).
For <n> years we have relied on this software technique in safety critical
systems around the world.

We should be afraid, very afraid.

Les

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: This calculation is just wrong / computer cant count!
    ... Therefore specific programming is required to cater for this. ... The reason is the limitations of IEE floating point arithmetic, granularity, ... By analogy ALL numbers in the 17 decimal places take part in the math so 7 ... what tolerance is GT prepared to accept before black becomes grey or any ...
    (microsoft.public.vc.mfc)
  • Re: demonic problem descriptions
    ... >> do not indicate a floating point number? ... to say that the existing mechanism and notation serves a nearly ... programming languages and is not likely to change any time in the next ... why MUST i care about float ...
    (comp.lang.lisp)
  • Re: why system providing routies will provide different result in C++ and Fortran
    ... > my main occupation is teaching programming ... > to the complete beginner to programming the actual ... even good trig functions can only return closest floating point ... >> Ian Chivers wrote: ...
    (comp.lang.fortran)
  • Re: demonic problem descriptions
    ... I suspect that of all the people who have ever written floating point ... FP hardware wanted inexact math without error bounds calculation by ... Lisp enables you to do many things, ... yes, Lisp is a programmable programming language, but you shouldn't ...
    (comp.lang.lisp)
  • Re: (* 2.4 3) => 7.2000003 WTF?! Lets Fix Lisp! Noob Programming Challenge
    ... Lisp covers up the fact that there is something funky going on under the ... it would be nice if the emerging IEEE decimal floating point ... "real" number representation of programming languages were a base 10 ...
    (comp.lang.lisp)