Re: This calculation is just wrong / computer can't count!
- From: Geeky Badger <spamhater@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 08 Oct 2007 15:50:02 -0500
It is the programmer's responsibility to do the rounding if a
repeating decimal results from division.
Given the OP's fixation on decimal I judged that at least he could see
that BCD was doing the same thing as his "accurate" calculator.
BCD also has the advantage of providing more significant decimal
digits.
-GB
On Mon, 08 Oct 2007 15:16:48 -0400, Joseph M. Newcomer
<newcomer@xxxxxxxxxxxx> wrote:
Unfortunately, packed decimal has exactly the same problem. While indeed you will get.
0.83333333333333333333333333333 (that's 31 digits of accuracy, if I counted right) for
the intermediate result, when you multiply this by 30 you get
24.99999999999999999999999999999
which is not 25. OTOH, I prove, in a later message, that in binary floating point
arithemtic, AS IMPLEMENTED ON THE PENTIUM FPU, as demonstrated by my Floating Point
Explorer,
0.83333333333333337 * 30.00000000000000000 = 25.00000000000000000
that is
0x3FEAAAAAAAAAAAAB * 0x403E000000000000 = 0x4039000000000000
which is MORE ACCURATE than the purported "correct maths", whcih produce an ERRONEOUS
answer. So it makes me wonder about who is or is not in contact with reality here...
joe
On Mon, 08 Oct 2007 11:23:46 -0500, Geeky Badger <spamhater@xxxxxxxxxxxxxxxxxxxx> wrote:
GT,Joseph M. Newcomer [MVP]
If you insist on getting an accurate answer in the decimal system,
then you should find a processor that supports Binary Coded Decimal
(BCD) math. The 8-bit 6502 had a bit for this. The IBM 370 family of
mainframes has BCD instructions (Add/Subtract/Multiple/Divide in
PACKED mode).
If you can't understand that using binary to represent decimal digits
must always lead to partial decimal digits then you are doomed to
argue like this forever.
There are three solutions to your problem:
1. Handle the partial decimal digit problems in your code by using a
floating point variable with sufficient significant digits and then
properly rounding.
2. Find a machine which supports BCD and use that for your
calculations.
3. State your problem in binary. Then the binary answer will be
accurate. :) You can easily prove this by finding a calculator that
supports binary and running the numbers on it.
-GB
On Mon, 8 Oct 2007 10:48:59 +0100, "GT"
<ContactGT_remove_@xxxxxxxxxxx> wrote:
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:rnhgg3tqi4f0np08ies2o9bviq4o4994jt@xxxxxxxxxx
See all my earlier posts. Your expectations are erroneous, and all your
problems stem
from a failure to understand reality.
Odd - reality states that 25/30, then * 30 is 25! My grasp on reality is
sound, yours seems to be away with the fairies!
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- 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: Joseph M . Newcomer
- Re: This calculation is just wrong / computer can't count!
- From: GT
- Re: This calculation is just wrong / computer can't count!
- From: Geeky Badger
- Re: This calculation is just wrong / computer can't count!
- From: Joseph M . Newcomer
- 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: MonthCalCtrl ... OnGetdaystate() ?
- 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
|