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

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




"GT" <ContactGT_remove_@xxxxxxxxxxx> wrote in message
news:00616abc$0$12577$c3e8da3@xxxxxxxxxxxxxxxxxxxx
"Les" <l.neilson@xxxxxxxxxxxxxxxxxxx> wrote in message
news:fed0ig$17u6$1@xxxxxxxxxxxxxxxxxxxx

"GT" <ContactGT_remove_@xxxxxxxxxxx> wrote in message
news:005c4583$0$2857$c3e8da3@xxxxxxxxxxxxxxxxxxxx
I have no idea why you are insisting that you are getting the wrong
answers. [snip]

Then you need to go back to primary school mathematics classes!

OK.
So hundreds of thousands of us programmers need to go back to school.
Millions of PCs need to be recalled because "the math is wrong".

Alternatively you could find a class or textbook on Numerical Methods and
computing.


What is 25/30?

In integer math it is 0
In floating point math 0.833333 approximately


I was going to try not to respond but ...

This is my point exactly - it is NOT 0.833337. That number is WRONG.

By your own argument :
0.8333330 is also wrong.
You (or the computer) has introduced an erroneous "0" at whichever point you
put the "truncation".


also

(a) guard bits (digits)
4 days ago, my first reply, the reference to Goldberg's paper. See the
section on "Rounding Error" it is very near the top, it covers just about
everything mentioned so far in this thread, including guard bits. Note it
also mentions they are a hardware implementation - ie not "some software
technique you can just use".
It also mentions the necessity and inevitability of approximation.
See also the section "Exactly Rounded Operations" which discusses guard
bits.
and the sections "Relative Error and Ulps", and "Guard Digits"


(b)
ab aa aa aa aa aa ea 3f = 0.83333333333333337

as I and others have mentioned this is the closest number to 25.0/30.0 which
is representable in binary/hex
So why can't it store or use 0.83333333333333330 ? (By your description, the
number you would prefer it to use)

(b.1 STORE:)
Well as I explained elsethread if you change the "ab" to "aa" ie zero the
last bit
you get :

aa aa aa aa aa aa ea 3f which is 0.83333333333333326
Oops this is less than 0.83333333333333330

so lets go back another bit
a9 aa aa aa aa aa ea 3f = 0.83333333333333315

and another
a8 aa aa aa aa aa ea 3f = 0.83333333333333304

If we can't get 0.83333333333333330
can we get 0.83333333333333300 ?
let's subtract another one bit.

a7 aa aa aa aa aa ea 3f = 0.83333333333333293
Oops we've gone too far again.
and so on.



(b.2 USE:)
What if I have in my program :
x = 0.83333333333333337;
y = 0.83333333333333326;


should the computer just drop or ignore the "7" or "26" as you have
requested it to do for your calculation?
then z = x-y = 0.0000000000000001 in my program
but = 0.0000000000000030 in yours


That would make the calculation inaccurate "330" minus "300" would be wrong
for my program if I am working to the LSBs.

I will repeat what I said at the beginning.
If your algorithm is sensitive to the inaccuracy of the LSB of floating
point numbers then you need to rethink / rewrite your algorithm.
I did not stress this point before, as I thought you merely didn't
understand about the limitations of floating point internal representation.

Les

For the record.
I am not a C++ wizard or expert by any means.
My primary language for 30 years has been Fortran. Before that Cobol and
some Assembler.
I access this newsgroup in order to learn about MFC and C++ techniques as I
am now having to maintain and develop software using these tools.



.



Relevant Pages

  • Re: This calculation is just wrong / computer cant count!
    ... Then you need to go back to primary school mathematics classes! ... Millions of PCs need to be recalled because "the math is wrong". ... In integer math it is 0 ... In floating point math 0.833333 approximately ...
    (microsoft.public.vc.mfc)
  • Re: This calculation is just wrong / computer cant count!
    ... Then you need to go back to primary school mathematics classes! ... Millions of PCs need to be recalled because "the math is wrong". ... and computing. ... I didn't put a zero on the end of the number - you just ...
    (microsoft.public.vc.mfc)
  • Re: This calculation is just wrong / computer cant count!
    ... Then you need to go back to primary school mathematics classes! ... So hundreds of thousands of us programmers need to go back to school. ... Millions of PCs need to be recalled because "the math is wrong". ...
    (microsoft.public.vc.mfc)