Monster: evaluate math expressions in strings
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.
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.
Never mind! I figured it out.
Just before the end of the main Eval function, I changed
y += 0.0
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)