Shoutbox

[?] Calculator in trouble! - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [?] Calculator in trouble! (/showthread.php?tid=69183)

[?] Calculator in trouble! by Matti on 12-05-2006 at 06:34 PM

Okay, you still remember my Calculator? And all the trouble we had with it?

Well, it returned. :P 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! :)
RE: [?] Calculator in trouble! by J-Thread on 12-05-2006 at 08:45 PM

code:
Token += this.charAt(i++ + 1);

Sorry for posting without giving a good answer, but that really hurts my eyes!! Please make it:
code:
Token += this.charAt(++i);


And this doesn't look Ok to me either:
code:
if (/^degrees?$/i.test(Angle)){
   Token = Func + "*180";
} else if (/^grad$/i.test(Angle)) {
   Token = Func + "*200";
}

RE: [?] Calculator in trouble! by Matti on 12-06-2006 at 03:38 PM

Okay, but that doesn't really fix the problem. (And what's wrong with the degrees/grad anyway?)
I'd like to ask Shondoit about it but I didn't see him in months. :(

Maybe someone else? :P