Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Monster: evaluate math expressions in strings


  • Please log in to reply
87 replies to this topic
Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Version 0.9 was written in an earlier AHK version. The latest version (1.2) should work with the last AHK version. Do you have AHK 1.0.48.05? Did you add anything to Monster, or modified it?

qjchen
  • Members
  • 7 posts
  • Last active: Aug 10 2013 12:44 PM
  • Joined: 13 Jun 2009
I do use Autohotkey 1.0.48.05
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.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Maybe your application does not copy ASCII text to the clipboard. Try the script in Notepad or MS Word. If it is the case, a check for the foreground application and text conversion is necessary. (To see if it is the problem add a line "MsgBox %ClipBoard%" after the "ClipWait 0.5" line - it should show "1+2".) It is also possible that your application is too slow to set the clipboard. In this case increase the time limit, to something like "ClipWait 3.0".

qjchen
  • Members
  • 7 posts
  • Last active: Aug 10 2013 12:44 PM
  • Joined: 13 Jun 2009
laszlo, thank you for your reply...

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%" "


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
I assume that you get the right string in ClipBoard ("1+2"), so the problem is not another AHK script or a clipboard manager.

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.

qjchen
  • Members
  • 7 posts
  • Last active: Aug 10 2013 12:44 PM
  • Joined: 13 Jun 2009
Thank you, laszlo, thank you for your answered my questions patiently.

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.

  • Guests
  • Last active:
  • Joined: --

pi*8 = 25.1327
pi+2 = 0
pi*1+2 = 5.14159
pi-8 = 0


Adding to pi seems to go wrong.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
With the latest AHK version (AutoHotkey v1.0.48.05), Monster 1.2 gives me the correct results on three different PCs:

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.

  • Guests
  • Last active:
  • Joined: --
Thanks for the response laszlo.The version was ok but the problem was solved pasting the code into notepad instead of PSPad.PSPad had as default UTF-8.

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

robertcollier4
  • Members
  • 141 posts
  • Last active: Jun 29 2017 12:42 PM
  • Joined: 11 Nov 2012
I have found that MonsterCalc 1.2 gives wrong answers when dealing with large numbers.
 
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.

nilsonrdg
  • Members
  • 31 posts
  • Last active: Jul 06 2014 04:02 PM
  • Joined: 27 Mar 2010

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



BGM
  • Members
  • 199 posts
  • Last active: Jun 05 2015 06:26 PM
  • Joined: 12 Jan 2011

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)


BGM
  • Members
  • 199 posts
  • Last active: Jun 05 2015 06:26 PM
  • Joined: 12 Jan 2011

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)