|
|
On 2001-02-07 17:23, Warp <war### [at] tagpovrayorg> wrote:
>Tom Melly <tom### [at] tomandlucouk> wrote:
>: I disagree - for example I am not offended/shocked/suprised/whatever
>: that entering 2+3*5 in a calculator gives me 25
>
> If I enter that in my calculator it gives me 17. Why?
>
> There are two (main) types of calculators Usually calculators only .
> calculate one operation at a time .
I would debate the "usually" here. Every calculator I have ever bought
(starting with that TI-33 over 20 years ago) knew about precedence
rules. The cheap thingies built into mouse mats and rulers probably
don't but they don't have parentheses either (for the same reason -
parentheses require a deeper stack).
An interesting variation are some printing desk calculators, which use
infix operators for multiplication and division and postfix for addition
and subtraction. So to compute 2*3 - 4*5 you would type
CLR 2 * 3 + 4 * 5 -
> Now, the most advanced calculators (mainly graphical ones, like mine)
>allow you to actually write long expressions (the whole expression is
>shown on the screen of the calculator) and the result is calculated
>only when you press '=' (or usually 'enter' in those calculators).
The TI-33 didn't. It calculated each subexpression as soon as possible.
So if you type 2+3* it would notice that * has higher precedence than +
and throw 2+ on the stack. If you continued typing 5-, it would first
complete the multiplication (giving 15) and further check the stack
for pending operations. Since + has the same precedence as -, it would
perform the addition, too.
The stack had a limited depth (6 entries, I think), but I rarely
exceeded it. That wasn't a high-end calculator at that time, either, it
costed only a few hundred ATS - an HP-42 was about 10 or 20 times as
expensive, IIRC.
hp
--
_ | Peter J. Holzer | All Linux applications run on Solaris,
|_|_) | Sysadmin WSR | which is our implementation of Linux.
| | | hjp### [at] wsracat |
__/ | http://www.hjp.at/ | -- Scott McNealy, Dec. 2000
Post a reply to this message
|
|