At 4:52 PM +0100 7/15/08, Ford, Mike wrote:
On 15 July 2008 14:33, tedd advised:
> Mike:
No reason to be rude.
I said:
"Round-off errors normally don't enter into things unless your doing
multiplication and division operations."
And that is not "Bull" -- it's true. You can add and subtract all the
floating point numbers (the one's we are talking about here) you want
without any rounding errors whatsoever.
Sorry, I do apologise if I came over too strongly -- there was no
intention to offend.
However, you really can't dismiss the effects of round-off errors on
addition and subtraction as lightly as that. It's simply not true that
approximations only occur at the point of doing multiplication and
division -- there *are* approximations involved in addition and
subtraction, and it is necessary to be aware that this is the case -- as
Jay proved, 0.1+0.2 is hardly ever exactly 0.3. In this sort of case, it
may well be that an appropriate degree of suspicion is simply to round
to 2 decimal places at every stage, or compare the absolute difference
to .001, but nonetheless one has to *know* that this is necessary.
Ummm -- sorry, better </rant>, now!!!
No problem about the rudeness -- email is a terrible form of
communication. Sometimes we don't realize how we are being perceived.
I know full well about what you speak and why there are problems
dealing with numbers.
My only point here was that the OP was talking about his
balance-sheet not balancing at the end of the day.
I said that if all he was doing was adding and subtracting, then he
wouldn't have any problems -- those operations are not subject to the
rounding errors that division and multiplication induce. And
experience has shown me that my claim is true. I can add and subtract
dollars and cents all day without an error whatsoever.
Now, if you get into more complicated math, such as
multiplication/division then of course rounding errors come into play
much more noticeably. It is true that not every number can be
represented in binary because of the limits of the processor. Take
for example pi, no computer in the world has capabilities to
represent that number in it's totality (i.e., unlimited precision).
However, if one defines the precision, then that's a different
matter. As with the OP's problem, the precision he was dealing with
was simply 0.00 and addition and subtraction operations don't come
into play at the precision level (i.e., 0.10 + 0.20 will equal 0.30
no matter how many times you add it).
In addition, the algorithm that used to round the number also comes
into play. For example php always round down and that introduces
bias, as proved here:
http://webbytedd.com/bbb/rounding/
So, all in all, I agree with your statements, but I just don't think
you fully appreciated what I was trying to communicate to the OP.
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php