Okay, you still remember my Calculator? And all the trouble we had with it?
Well, it returned.
Since I'm working intensively on it to get it ready for the contest, I bumped on probably the craziest problem I ever had with it.
When I try to calculate this:
quote:
-Sin(2)
it fails. The problem lies in this line of code:
code:
if (typeof(Math[Token.toLowerCase()])=="function" || eval("typeof("+(Token.toLowerCase())+")=='function'")) {
since
Token has a value of
"-Sin" and thus the first statement fails and the second returns an error. (
"typeof(-Sin) == 'function'" doesn't work because of the negation sign) I did note that Shondoit, the original creator of the calculating functions (<3), already tried to fix this by using:
code:
var firstChar = this.charAt(i-Token.length);
...
if(firstChar == "-") Token = "-" + Token;
but that's placed
in the if-statement and it doesn't seem to work outside it either. Soo... if some very clever person reads this and takes a look at the functions, I'd appreciate it enormously if you can give some hints to fix it.
The attachment contains a snip from my code which executes the calculations. To use it, use something like this:
code:
var str = "-Sin(2)";
Debug.Trace(str.Calculate());
Thanks in advance!