# Monster: evaluate math expressions in strings

and I does not add anything to version 1.2

I just copy all the code, and run it.

But it always give an answer of -1.

Thank you very much.

I do as your advise.

But I find that in my PC, this line is strange

RegExMatch(x, "(.*[^!\~±?\@\*/\\])(±|?)(.*)", y)

it return nothing when I just like select "1+2" to test

just like this following code cant get the right answer, the %test%, %y1% and %y3% are all empty.

I am not sure whether my AUTOHOTKEY version is right, but in the HELP file it says that it is 1.0.48.05

d="111111111±222" test:=RegExMatch(d, "(.*[^!\~±?\@\*/\\])(±|?)(.*)", y) MsgBox "test"%test%"" "%y1%" "%y3%" "

You could test directly the expression evaluation with adding a line to the top of the script

MsgBox % Eval("1+2")

If it does not show 3, then there could be problems with AHK. You have to uninstall it then do a fresh install from the AHK main website.

But when I MsgBox % Eval("1+2") directly in Autohotkey 1.0.48.05, it also get the wrong results.

Maybe something get wrong in my PC, let me try it carefully.

Thank you very much.

pi*8 = 25.1327

pi+2 = 0

pi*1+2 = 5.14159

pi-8 = 0

Adding to pi seems to go wrong.

pi*8 = 25.1327

pi+2 = 5.14159

pi*1+2 = 5.14159

pi-8 = -4.85841

Check if you have the right SW versions.

Thanks for the great function i use it (as part of another code) every day!

**TEST CASES**

__1. Multiplication of large numbers__

Eval("2343423 * 4192") gives answer of "9.82363e+009". If I were to convert this answer from scientific to decimal notation, makes me believe the answer is 9.82363 * 10^9 = 9823630000

WRONG - answer is 9823629216

__2. Division of large numbers__

I came across this when making some aligned partitions. I wanted to check if a certain starting partition sector number was divisible by 4192 or not.

Eval("913860600 / 4192") gives "218001" - no decimal point reported, so that must mean that the first operand is an even multiple of the second operand and the partition is aligned.

WRONG - I tried it out with Windows calculator, the answer is 218001.097328. The partition is not aligned at a 4192 boundary.

But MonsterCalc made me think the answer was an even integer! ERROR.

Due to these problems, I have switched to calc() from derRaphael which gives large results accurately.

It only works when compiled. When not compiled, 1 + 2 resulted in 12, for example.

How can I make monster return "" instead of 0 when it encounters an equation it can't calculate?

For example, 2+2+ is not a complete equation - I want it to return ""

(AutoHotkey 1.1.15.00 on Windows 7 Pro x64)

Never mind! I figured it out.

Just before the end of the main Eval function, I changed

y += 0.0

to

if(y != "") ;test for "" because we don't want to return 0 for an expression that cannot be calculated, such as 2+2+ which is incomplete and should not return 0

y += 0.0

(AutoHotkey 1.1.15.00 on Windows 7 Pro x64)