PDA

View Full Version : [Ver 1.0] Ext.ux.Calculator



tjstuart
30 Jul 2007, 7:39 PM
Version 1.0 of Ext.ux.Calculator released. Feel free to comment, suggest changes or enhancements etc.

http://extjs.com/learn/Extension:Calculator

franklt69
31 Jul 2007, 4:21 AM
tjstuart congratulations I am watching your web site demo now, later I will test the calculator using ext2, now some remarks, in you demo, the staticCalc appear overlay the triggerForm, I am using FF2, the same with IE6.

regards
Frank

tjstuart
31 Jul 2007, 4:10 PM
in you demo, the staticCalc appear overlay the triggerForm, I am using FF2, the same with IE6.

Frank,

I assume you mean that when one presses the trigger to popup the calculator it appears "over" the static calculator. I am aware of this and for the sake of the demo I didnt think it mattered. I am merely demonstrating how one can use the calculator.

Cheers, and let us know how you go with Ext2

Toby

jsakalos
1 Aug 2007, 2:23 AM
Very nice, I like it. Also the idea of integrating it with text field.

Suggestions:



1 + 2 * 3 should equal 7, not 9
add CE (clear entry/last digit) key
keymap also for non-numpad + - * / keys
some visual feedback that button was pressed if keyboard is used

Keep up, good idea nicely done. =D>

tjstuart
1 Aug 2007, 4:33 PM
Thanks Saki good suggestions. I actually never bothered to test precedence (bracketing) ie. your example 1 + (2 *3) ... but hey, since when did programmers test their *own* code ;) Actually now that I think of it I wrote it only to handle two operands as that was our basic requirement. I'll look into incorporating your suggestions in next version.

Thanks again

Regards

Toby

evant
1 Aug 2007, 4:37 PM
I disagree with the precedence thing.

Open up windows calc, do 1 + 2 * 3, gives you 9, that's the usual behaviour on a binary calculator.

jsakalos
1 Aug 2007, 5:14 PM
I disagree with the precedence thing.

Open up windows calc, do 1 + 2 * 3, gives you 9, that's the usual behaviour on a binary calculator.

Although I understand that you disagree, that's mathematical rule. There are many software and hardware calculator that don't obey it but that doesn't change the rule. It just distinguishes good calculators from bad ones - I would never buy one that gives wrong results.

PS: I cannot open windows calc as I run Linux and my KCalc gives correct result.

evant
1 Aug 2007, 6:37 PM
Understood, however this is a BINARY calculator, it should not remember more than one operation at a time, nor would I except it to. It should immediately evaluate the operators on either sides of the operand and return a result.

If it doesn't do this, it should allow the user to see some kind of history of what you've inputted into the calculator.

tjstuart
1 Aug 2007, 7:06 PM
Understood, however this is a BINARY calculator, it should not remember more than one operation at a time, nor would I except it to. It should immediately evaluate the operators on either sides of the operand and return a result.

If it doesn't do this, it should allow the user to see some kind of history of what you've inputted into the calculator.

I may add an "advanced" mode at some stage that would allow for this kind of thing. I'm pressed for time at the moment and as it is at the moment the Calculator suits our requirements perfectly.

I think the most useful feature would be (as suggested by Saki) ... "some visual feedback that button was pressed if keyboard is used" ... and I will probably add that first.

brian.moeskau
1 Aug 2007, 7:47 PM
Agreed with Evan. If the calculator totals after every operation, as this one and Windows calc both do (and Mac's dashboard calc as well), then 1 + 2 = 3, 3 * 3 = 9. I would say that since it is consistent with the default OS calcs for Win and Mac, it's probably just fine ;)

jsakalos
2 Aug 2007, 1:53 AM
Hi Brian and evant,

I don't want to argue or invalidate Toby's work. The only purpose of mine is to make things better.

Let's imagine we have simple shopping list task: We buy 2 pcs of article A $3 each and 5 pcs of article B $8 each. We should pay $46, right?

We need result of 2 * 3 + 5 * 8.

Now: 2 * 3 + (you get correct 6 here) 5 * (you get 11 here) 8 = 88 (wrong result).

There is no chance to get right result out of it without running "a correction subroutine" in our minds and writing down partial results, like 2 * 3 = 6 (write down), 5 * 8 = 40 and 40 + 6 = 46. (I've used integers here for simplicity so we can remember 6 or 40 but calc is usually used when we have floats.)

So, if we tried to pass such calculator through a primary school math test it would get D. Disobeying basic math rule(s) and delivering such calcs as standard OS calculators is decision of Windows team and Mac team but they don't give right results only because they are in Win or Mac.

Ext can be better.... :)

Foggy
2 Aug 2007, 3:49 AM
BTW if you change the view of the windows calc to academic, 1 + 2 * 3 would result in 7 ;)
In the standard view it results in 9 :)
So what we are, standards or academics? :D

And PHP does it also on the (in my opinion) right way:


<?php
echo 2 * 3 + 5 * 8; // 46
echo '<br />';
echo ((2 * 3) + 5) * 8; // 88
?>

So i agree with Jozef

Greets Claudio

TommyMaintz
2 Aug 2007, 4:28 AM
I also agree with Jozef. I always find it very annoying when calculators dont follow the mathematical rules

Nullity
2 Aug 2007, 6:00 AM
Jozef is correct with mathematical rule, however, you are trying to compare two different types of calculators; standard and scientific (sometimes called other things, but you get the idea).

As far as a standard calculator goes, this Ext extension is spot on and works exactly as it should. It's not supposed to try to evaluate expressions. A standard calculator evaluates at one operand at a time as they are entered. The user must work out operational precedence on his own before starting the calculation. All standard calculators work this way, software or hardware.

Now if tjstuart were to add a scientific/advanced "mode" to his calculator, then I would expect it to work as Jozef suggests. In that case, one should be able to enter an entire expression (2 * 3 + 5 * 8) and hit "Equals" before it is evaluated; where operational precedence is taken into consideration.

Good job, Toby. I was going to write a calculator myself, now I may just use yours =D>

jsakalos
2 Aug 2007, 6:23 AM
All standard calculators work this way, software or hardware.



Well, I know at least one standard software calculator (KCalc) that doesn't (which means it gives always correct results regardless of standard/scientific mode). Also I have one hardware calculator that gives correct results. (I don't buy another).

You see, this is not a question of mode or a question of opinion if it should work that way or another. It's also not question if rule is good or bad or what do I think about rule. Rule is there and it is to be obeyed.

It is pure question of wrong or correct.

Nullity
2 Aug 2007, 6:45 AM
KCalc is a scientific calculator, not standard (I am also running linux). I also have several hardware calculators, some standard, some scientific. I agree that it is a matter of what is correct, and the answer is; they both are. Standard calculators are meant to be simple - used to find basic sums. Scientific calculators exist to do much more advanced math.

Think about it, if standard calculators were "wrong", don't you think they would have been corrected in the 50-some-odd years since the electronic calculator was introduced?

jsakalos
2 Aug 2007, 7:13 AM
You see, people believed for ages that Sun turns around Earth and that Earth is flat. What people think, even the majority of them, doesn't change the truth.

And the truth is that I'd never be through my primary school if I thought that 2 * 3 + 4 * 5 = 88. If a calculator thinks it's 88 I don't want it regardless others may do.

brian.moeskau
2 Aug 2007, 7:17 AM
Everyone arguing that this "violates mathematical rules" is incorrectly assuming that the implementation is a scientific calculator. It's not. So you can argue all day long that every calculator implementation should be scientific -- that's your opnion. But arguing that a calculator that is built to provide individual calculations is wrong because you choose to enter your calculations in an order that assumes precedence where there is none is just silly. Using standard calculators, every operation is separate, and it is up to you to provide each operation in the order that is required. It's really pretty simple :)

jsakalos
2 Aug 2007, 7:37 AM
Everyone arguing that this "violates mathematical rules" is incorrectly assuming that the implementation is a scientific calculator. It's not. So you can argue all day long that every calculator implementation should be scientific -- that's your opnion. But arguing that a calculator that is built to provide individual calculations is wrong because you choose to enter your calculations in an order that assumes precedence where there is none is just silly. Using standard calculators, every operation is separate, and it is up to you to provide each operation in the order that is required. It's really pretty simple :)

OK, Brian,

I'm not going into this any longer. It's up to everybody to make up his/her own minds and make their own decisions. Anyway, I've already said all what I wanted.

tjstuart
2 Aug 2007, 3:55 PM
I think you are all correct :D

But as this is a basic calculator (read non-scientific) it does its job. In our insurance/claims management application the calculator is required for trivial calculations that simpletons cannot compute in their head eg. monthlyPay / 4 ... and to this end it serves its purpose.


Good job, Toby. I was going to write a calculator myself, now I may just use yours =D>

Thanks Nullity and if you choose to extend or enhance it please let me know as I will add it to the next release.

Cheers

Toby

JeffHowden
2 Aug 2007, 6:30 PM
Windows calculator does not total after every operation. I key in exactly 1 + 2 * 3 and receive the correct value of 7. Granted, I run Windows calculator in scientific mode by default and the standard mode does seem to give the incorrect value (how quaint). So, apparently in standard mode, it totals after every operation, but in scientific mode it does not.