|
Posted by Andrew on December 5, 2007, 6:09 pm
Please log in for more thread options
R. C. White wrote:
> ...
> (John's parenthetical remark that I might be able to demonstrate the
> effect of timing on rounding apparently refers to the sequence of
> your arithmetic. For example: 100 * 2/3 = 67, right? Yes, if you
> multiply 100 times 2 first, you get 200, then divide 200 by 3, you
> get 66 2/3, which rounds to 67. Or if you divide 100 by 3 you get 33 1/3,
> then multiply times 2
> to get 66 2/3 or 67 again. But if you round the 33 1/3 after
> dividing and before multiplying, you get 33 times 2 equals 66 - not
> 67. So the sequence of your arithmetic AND your rounding is very
> important. As a general rule, always multiply first, then divide -
> and round only the final result. That's grade-school arithmetic, but
> easy to forget unless we have to work with it on a daily basis - like
> an accountant does.)
Remember computers work in binary, not decimal. (Except when using BCD
(binary coded decimal), but that's a whole different matter and indeed,
might only refer to IBM mainframes - the only 'true' computers, but I
digress....). In the good old days, one could write a BASIC program such
as:
10 FOR I=.1 TO 1 STEP .1
20 END I
and the loop would run 11 times because in the little computer's mind, 10 x
.1 doesn't equal 1! A little shy. Ah yes, ain't mathematics wonderful.
And if a computer can't get that 2 line program right, how can we and FIs?
:-)
(PS: It's been a long time since I wrote in BASIC; I hope I got that syntax
correct.)
--
-------------------------------------------------------------
Regards -
- Andrew
|