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



I have no idea whatsoever why you are using the word "wrong". Now you've introduced the
word "unreliable". WHAT PART OF WHAT WE HAVE ALL BEEN TELLING YOU ARE YOU MISSING?

The answer is correct. The answer is UTTERLY DETERMINISTIC and COMPLETELY RELIABLE. The
fact that it doesn't conform to your delusional system of decimal arithmetic is your
problem, not the computer's.

You cannot tell it to use 10 decimal places. You always get the precision of the
underlying floating point representation. Yes, you can play some games that will
perpetrate an illusion of less precision, but note that these introduce NEW artifacts of
errors, which will typically be substantially WORSE roundoff errors than what you are
currently seeing.

Please, stop whining and get in touch with reality.
joe

On Fri, 5 Oct 2007 10:38:10 +0100, "GT" <ContactGT_remove_@xxxxxxxxxxx> wrote:

"Les" <l.neilson@xxxxxxxxxxxxxxxxxxx> wrote in message
news:fe4rpq$1m7i$1@xxxxxxxxxxxxxxxxxxxx

"GT" <ContactGT_remove_@xxxxxxxxxxx> wrote in message
news:0057ac41$0$11709$c3e8da3@xxxxxxxxxxxxxxxxxxxx

We all know computers are binary machines, not decimal, but why can't the
computer do the same basic maths as a pocket calculator?!?

Hand calculators (and I believe the calculator in Windows) use internal
decimal arithmetic.

0.833333 is not representable in binary.

If you need your program to work with full accuracy and precision to 17
decimal places then you will need to write your own package working in
decimal math, or as Luke said

"find an arbitrary precision math library on the web and use it."

As I have already said, I don't need precision to 17 decimal places - 5 or 6
would be sufficient. I am just doing a series of basic calculations. Using
floating point doesn't help - it just brings the erroneous digit closer to
the decimal point.

I would like to know how to use the basic C++ datatypes and where the last
digit is 'wrong' or 'unreliable', just don't use it. Everyone keeps saying
'just use the digits you can rely on', but how? I have a double
effortChangeProportion which has 15 or 16 decimal places. HOW do I tell it
to just use the first 10 decimal places, thereby dropping the final digit
which is knocking out my calculations? I can't find any methods on a double
which tell it to truncate digits.

In order to drop the last digit, I have tried multiplying my number by 1
million, storing it in an int, then dividing by 1 million in order to remove
any trailing digits, but of course, the divide by 1 million still introduces
an unwanted digit at the end. I understand the theory, but how do I get
around it simply without having to find maths libraries. You shouldn't have
to use maths libraries for some basic multiplication and division! I can
understand maths libraries for Sin curves, bezier plotting, complex numbers
etc, but double effortChangeProportion = 25/30; is about as basic as maths
can get - if the language's basic data types can't handle x digits, then it
should use, store, manipulate and display x-1 digits instead!

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!
    ... I am just doing a series of basic calculations. ... digit is 'wrong' or 'unreliable', ... around it simply without having to find maths libraries. ...
    (microsoft.public.vc.mfc)
  • Re: Rounding errors
    ... Take for example 10 random single digit numbers. ... if you take a set of large precision random numbers between ... The rounding to 2 digits will restore the full count 500,500. ... But it is not the _roundeing_ that is wrong, it is the truncation to ...
    (comp.lang.cobol)
  • Re: Another question about big floating point
    ... I've been programming that bignum floating point thing I've talked ... We just lose a whole 32-bit dword "digit" from the number's ... effectively only 32 bits of precision)? ... annoyances of the hex float historically used by S/ ...
    (comp.programming)
  • Re: This calculation is just wrong / computer cant count!
    ... The guard bits answer has nothing to do with answering your question. ... that these conversions introduce. ... but the final digit is a 3. ... how do I get my calculations to work as accurately as the Windows ...
    (microsoft.public.vc.mfc)
  • Re: An uncountable countable set
    ... but it may depend on the ordering of the calculations. ... the diagonal number it does not matter what digit you calculate first. ... to which every path will lead is always the same: The set of rationals ... You state, explicitly, that they were not binary representations, ...
    (sci.math)

Loading