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



Being a FORTRAN programmer is clearly to your advantage. When we learned FORTRAN (which
was also my first language) these things were carefully explained to us. We did not have
the same delusional expectations as the OP because we knew better.

Apparently he is incapable of learning anything. We've tried. He just won't give up his
delusional system.
joe
On Mon, 8 Oct 2007 15:02:01 +0100, "Les" <l.neilson@xxxxxxxxxxxxxxxxxxx> wrote:


"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.


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



Relevant Pages

  • Re: Why float is called as float, not real?
    ... My guess is that "floating point" was used to distinguish the data representation from "fixed point." ... The oldest computer languages I've used, FORTRAN and ALGOL, both use "real," but as Glen noted, that wasn't the case with primeval FORTRAN. ... As Gib noted, even with a countably infinite number of bits, computers couldn't come close to representing all of the reals. ...
    (comp.lang.fortran)
  • Re: help reading fortran generated binary data...
    ... >> Helmut Giese ... That would probably have been Arjen, Tcl's FORTRAN guru:) but he ... floating point values as raw binary data, so I am only guessing here. ... read them back in using programs compiled with the same compiler - ...
    (comp.lang.tcl)
  • Re: Fortran vs. C++ : Which is best to choose now i
    ... Your perceived clash between the treatment of floating point and integer ... genericity than language committees' opposition to the ... It has taken Fortran 20 years to provide support for ieee fp error ... How long more does one have to wait for integer overflow ...
    (comp.lang.fortran)
  • Re: Batch file revisited
    ... > victory over English and the day that Rubber is patented) ... I was born 10/10/49, and my first language was FORTRAN on punch cards, input ...
    (borland.public.delphi.non-technical)
  • Re: Looping using iterators with fractional values
    ... As an historical aside, Fortran had loops ... The Fortran standards committee is very conservative about ... with floating point variables are so error-prone -- and alternatives ...
    (comp.lang.python)