Re: This calculation is just wrong / computer can't count!
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 06 Oct 2007 23:02:25 -0400
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 messageJoseph M. Newcomer [MVP]
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!
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- References:
- This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: AliR \(VC++ MVP\)
- Re: This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: Les
- Re: This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: Les
- Re: This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: Les
- Re: This calculation is just wrong / computer can't count!
- From: GT
- This calculation is just wrong / computer can't count!
- Prev by Date: Re: This calculation is just wrong / computer can't count!
- Next by Date: Re: This calculation is just wrong / computer can't count!
- Previous by thread: Re: This calculation is just wrong / computer can't count!
- Next by thread: Re: This calculation is just wrong / computer can't count!
- Index(es):
Relevant Pages
|
Loading