Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Be aware of a Calculator widget bug' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Be aware of a Calculator widget bug
Authored by: mcroft on May 24, '05 11:14:48AM

Well, it's just javascript. I'm at work and can't mess with the source, but it may not be too hard to modify.

Of course the other possibility is that becuase of how they implemented the JS, it's unfixable and would need a re-write.

Anyone looked under the hood?



[ Reply to This | # ]
10.4: Be aware of a Calculator widget bug
Authored by: Spartacus on May 24, '05 11:49:08AM
Well, it's just javascript. I'm at work and can't mess with the source, but it may not be too hard to modify.

It will probably be harder than you think.



[ Reply to This | # ]
Implementing PEMDAS
Authored by: colter on May 24, '05 12:28:24PM

Probably harder than you think.

I agree. As the user enters numbers and operators, you've got to keep track of what's been entered and what's okay to calculate now. With left-to-right entry and evaluation, you can evaluate expressions as the user enters them. This is probably why Apple went with LTR over PEMDAS -- it's easier to implement.

To implement PEMDAS, you really need to have parenthesis available, or you're not able to use the intermediate result of a lower-order calculation as an operand to a higher-order calculation. For example, 2 * (1 + 3) or 3 ^ (4 - 1). Actually, I'm not sure you can do those with LTR, either, without parenthesis. This is where postfix evaluation comes in so handy. :) 2 1 3 + * and 3 4 1 - ^ and you're done. ;)



[ Reply to This | # ]
Implementing PEMDAS
Authored by: mcroft on May 24, '05 08:29:14PM

Not really, all you're doing is building a string to send to the JavaScript eval() function. The engine handles PEMDAS just fine and since there aren't buttons for P and E, it's limited right now to the rather simple MDAS.

I've got it working for addition right now. I need to make it smart enough to not add a second operator if the last item is already an operator. Once it's working, I need to add a preference [Delayed Execution/Immediate Execution], a flip to the backside button and a backside, and then let some of you test it.



[ Reply to This | # ]
Implementing PEMDAS
Authored by: mcroft on May 24, '05 10:06:31PM

I've got the JavaScript done for a drop-in replacement if anyone wants it. I'll start messing with a polished implementation with a setting on the back et. al., but I've done a lot more JavaScript than I have widget work, so I don't know when it will be done.

powers are more difficult, but not out of the question (eval won't handle them intrinsically).

email me and I'll send you the modified calculator.js.

It's also pretty clear how you'd use this for RPN



[ Reply to This | # ]
Implementing PEMDAS
Authored by: mcroft on May 25, '05 01:15:48AM
Option Enabled MDAS awareCalculator Widget variant.

[ Reply to This | # ]