See below...
Post by GTPost by Luke alcatelI'll risk criticism by saying this thread is silly. A middle school child
learns not to express calculation results with more significant digits
than the data or instruments provide. A double provides 14-15 significant
digits so why are you surprised that the result is not what you
theoretically expect at the 15th digit?
I am surprised because I am using a C++ basic data type and it shouldn't
stumble over basic mathematics!
***
May I say at this point, after seeing all the explanations, that this now constitutes a
stupid remark. In case you missed the reality check, YOU ARE GETTING THE CORRECT ANSWER
AND YOUR EXPECTATIONS OF MATHEMATICS ARE ERRONEOUS. Fix your expectations. Stop whining.
*****
Post by GTPost by Luke alcatelClue #1 adjust your print formats for fewer significant digits.
This number is the first stage in some complex calculations and the problem
is compounded resulting in a final number that is just wrong.
****
When I was working on my PhD in 1974, and in case you need help in arithmetic, that was 33
years ago, not counting the roundoff errors intrinsic in the computation, I went to Joe
Traub, then one of the world's experts on floating point computations on computers, and
asked him about issues of optimizing floating point computations. His answer: "don't.
During some computations, we end up introducing errors that are actually orders of
magnitude higher than the final result, but we carefully do other computations that cancel
them out, so we get the correct result at the end. If you change the order of computation
in any way at all, you change the computation we have carefully designed". So the people
who ARE in contact with reality, which is apparently everyone who does serious floating
point, have understood this problem for decades. Just because you don't understand the
problem, and have no contact with reality, don't complain to us that you are getting
"incorrect" or "undependable" results, or even that it doesn't correspond to your
delusional system of mathematics. It is a completely self-consistent form of arithmetic,
and if it displease you, then you will have to expend massive effort and computational
cost to produce something that actually implements your delusional system. The correct
solution is to do what has been done for the last 60 years of numerical computation using
computers, and come to terms with the concept of roundoff error, which is intrinsic to
finite-precision arithmetic. You will have to understand that you cannot EVER compare any
floating point result to any other known value, whether it is 0 or any other value, and
expect to get equality. You will ALWAYS compare to a "fuzz factor". If your algorithm is
sensitive to the fact that you get a very tiny negative value, then your algorithm is
WRONG, and you will need to fix it. If you print out a very tiny negative number of fewer
digits of precision and get a minus sign, then your printout is wrong. You will have to
do what tens of thousands of programmers have done for decades, and actually learn what
floating point arithmetic is all about. If you persist in your delusional system, you
will have no success, because you are clearly not in touch with any form of reality that
programmers actually deal with on a daily basis, and your program will never work, because
it will always be based on erroneous assumptions.
****
Post by GTPost by Luke alcatelClue #2 don't try to land on Jupiter if your flight control software uses
doubles but your navigation system requires 18 significant digits.
I only require about 5 or 6 decimal places, but float and double both see
the same problem, so what am I supposed to do?
****
LEARN HOW FLOATING POINT WORKS! ADJUST YOUR ATTITUDE SO YOU TAKE REALITY INTO
CONSIDERATION AS PART OF YOUR PROGRAMMING.
*****
Post by GTPost by Luke alcatelClue #3 find an arbitrary precision math library on the web and use it.
I found one - its called the basic C++ data types. int, float, double etc.
****
No, you have not. The fact that you think that basic C++ data types such as int, float,
double etc have arbitrary precision shows that you are totally clueless. Note that there
has been a serious effort to educate you, and you are rejecting reality because it doesn't
conform to your delusions. Well, that loses. And you will continue to lose as long as
you fail to understand reality. Your expectations are entirely and completely delusional.
No form of reality in the history of computing has conformed to your delusions, although
there have been sincere attempts to do so over the years, none have ever proven to be
effective in practical computations. Sure, you can use infinite precision arithmetic
packages to compute the value of pi to three billion digits if you want, but you know,
there really isn't very much call for three billion digit arithmetic otherwise.
****
Post by GTWhy is everyone having a go at me? I asked a perfectly simple question that
is confusing 3 of us here. In front of me, I have a casio calculator, a
pencil and paper and a PC. I type some numbers into the calculator and
scribble on the paper and derive 5 numbers. The first stage in the
calculation is 25/30. The calculator gives us range of 5 number that
match/confirm what we worked out on paper, but the PC gives us something
else that is just wrong. We are not working on a low level C system here, we
are writing an MFC application with dialog boxes, menus and the likes. There
is not a printf in sight.
****
And we gave you a perfectly simple answer. Your view of reality is wrong, and until you
change your view of reality, you will never find a computer that matches your delusions.
Perhaps what you need to do is build a robotic arm that punches buttons on your
calculator, and a video camera to read the result, and OCR recognition to handle it, but
you know, as arithmetic units go, that's going to rather slow. Or, perhaps you could
create a robotic system to use a slide rule. Ultimately, as long as you want to use float
or double, you are going to have to understand the limits of binary floating point
representations, and your continuing refusal to do so shows that you have unreasonable
expectations that can never be met by any floating point unit on any computer in history,
so all we see now is someone whining that reality doesn't match your delusions, and
refuses to accept what everyone has been telling you.
****
Post by GTOne of the results should be exactly 0, but the computer gives the
result -0.00000000007. Which is then displayed on the screen as -0.0. This
result is displayed on the screen (in an edit boxes) along with all the
positive numbers and is just wrong!
****
See my earlier comment. This is a correct result. Your expecations is wrong.
****
Post by GT25/33 = 0.833 recurring. 0.833337 is not *innacurate* it is *WRONG*. End of
story.
****
25/30 =
0.833333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
is not only *inaccurate*, it is *wrong*. Why do you think the value you are talking about
is any less inaccurate or is any more wrong. Given any finite representation of digits,
it is IMPOSSIBLE to represent 25/30 correctly. Why is one inaccurate representation good
while another inaccurate representation is bad? Simple: YOU ARE CLUELESS. And you are
absolutely refusing to understand reality.
*****
Post by GTEven if this 0.83333..3337 were true, then adding 1.0 to it CANNOT BE
1.8333...335 - it has changed the last digit!!! If it can't handle the last
digit, then it shouldn't display/use it.
****
I actually explained that in an earlier message. It boils down to the fact that you are
persisting in believing that computers do decimal arithmetic in spite of massive evidence
to the contrary, and in spite of the fact that many people have attempted to explain to
you WHY you are wrong. The answers you are getting are CORRECT.
So stop whining that binary floating point doesn't work like a piece of paper and pencil.
It doesn't, it never did, it never will, and your belief that it should is completely
inconsistent with reality. So what needs to change is your attitude.
Every other programmer who has done floating point has understood reality, so why do you
think that you are so privileged that the computer has to conform to your reality?
*****
Post by GTIf the computer can work to 8, 12, 15, 16, 18 digits, then why does it get
the last digit wrong?
*****
Why do I get a negative value when I do
2147483647 + 1
If I expect an int to hold more that the value 2147483647 then my expectations are wrong,
and my grasp of reality is wrong. It is no more valid to expect that
2147483647 + 1 = 2147483648
than it is to expect 25/30=0.833,333,333,333,33
****
Post by GTI understand all this significant digit stuff, my problem is - Why does the
computer store and use the 'dodgy' last digit if it is actually WRONG and
causes incorrect results?
****
Your whole concept of WRONG is wrong. Your whole concept of "dodgy" is wrong. Your
concept of arithmetic is wrong. We are trying, seriously trying, to educate you that what
you are seeing is RIGHT and only your expecations are wrong, and you keep missing the
point.
joe
****
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm