AutoHotkey Community

It is currently May 26th, 2012, 7:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 81 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next
Author Message
 Post subject:
PostPosted: April 4th, 2007, 11:26 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
I like the name too :8)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2007, 4:00 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
AHK version 1.0.46.12 introduced the long awaited scientific number formats (1.23e-7). They allow using full 64 bit precision in intermediate results, so there will be no loss of accuracy when some values are too small.

Monster is digit-sequence oriented, that is, each partial result is converted to a string of digits, replacing the sub-expression just computed. This is why scientific number representations are so important. In fix point representation small numbers get truncated, and lose precision. Even if later they get multiplied by a large number, some least significant digits are lost.

Unfortunately, scientific number representations introduce complications in the script. Now e is not necessarily a variable or operator, and the operators + and - have 4 different meanings, dependent on the context:
- sign of a number (-2)
- sign of the exponent (1.23e-7)
- unary operator ( -x )
- binary operator ( x-y )

In version 1.1 of Monster these are handled by distinguishing early on between the different roles of + and -. Internally, they get replaced by ± and ¬, respectively, when they are operators. To avoid humongous regular expressions, in the pre-processing phase scientific numbers are enclosed between ‘ and ’, which are later removed for speed and simplicity. The AHK requirement that scientific numbers must contain decimal points are lifted: 1e3 is valid.

For the users' perspective the only changes are improved precision and the support of scientific number notation, also in the output, by $6g or $9e type directives. Again, there are a lot of significant internal changes, so be careful and report problems!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 30th, 2007, 11:53 pm 
Offline

Joined: July 15th, 2007, 1:43 am
Posts: 1320
How about adding this math function for Arithmetic Sequences:

Code:
/* Example
MsgBox,, nado, % nado(5, 5, 5) ; 25
*/

nado(n, a, d)              ; a + (n-1)d
{
   Return a+(n-1)*d
   }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 31st, 2007, 1:43 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Three-operand functions are not (yet) supported. If you need to compute the entries of many arithmetic sequences, you can add your own construct for it, like a+n__d (where __ is an operator, returning n*d-d), but it is not so common that justifies a new reserved symbol.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2008, 9:37 pm 
Am I missing something or do PI and e give a result of 0 in the current version? Also, the binary conversions don't work for me.
Everything else I tried works.

These were evaluated in line:
pi = 0
e = 0
TOBIN(35) = 35
FROMBIN(10010) = 10010


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2008, 10:05 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Pi and e work for me. I ran the script as it is in the first post in this thread. Select somewhere the two letters "pi" and hit the hotkey Ctrl-Win-=. You will see "pi" changed to "pi = 3.14159".

ToBin and FromBin are internal functions. They are not exported. If you want to convert binary numbers to decimal, use "'10010". It will turn to "'10010 = -14". The opposite direction: "$b 35" becomes "$b 35= 0100011".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2008, 10:53 pm 
I decided to try it again in it's own script instead of within Autohotkey.ini and everything worked just fine. Something else must have gotten in the way.

Thanks for the help Lazlo.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 9:09 am 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Hi Laszlo,
I got to know of a small bug in the function where hex numbers are being evaluated. Have a look:
0x12 -> 18 [OK]
0xE1 -> 225 [OK]
0x1E -> 1 [ERROR]

From here.

Thanks,
Rajat

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 8:36 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Thanks, Rajat! I fixed the bug in the first post. The order of converting hex to decimal, and adding a missing decimal point to scientific numbers was swapped in the Eval(x) function. (Only this function needs to be patched.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2008, 10:56 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Thanks a lot Laszlo for the prompt fix, and ofcourse for the great function itself! I replaced the function in nDroid, and the new one is available. :)

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2008, 4:13 pm 
Nice script! THX

I've one question and 2 suggestions^^

First the question: How to square? I didn't find the function somehow...I normally would try 2^2, but this is used in another way.

* it would be great if all brackets which are open at the end of the calculation would be closed automatically. Example: "sin(0.5" to "sin(0.5)"

* another thing would be the automatic multiplication. for example 3a should be the same as 3*a, or 3pi the same as 3*pi.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2008, 4:27 pm 
Squaring is simple. 3**2 (3 to the power 2) gives 9


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2008, 4:44 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Monster uses the AHK notation for the power operator: 5**2 = 25, because ^ is used for XOR. There is also the shorthand, 5@2 for powers.

We can correct a few syntactic errors in the expressions, like adding missing parentheses, but it might cause more harm than good. If you type “sin(x + 1” and meant “sin(x)+1”, you get unexpected results. But, the result is wrong in the current version of Monster, too. Decent error handling could be more useful, which is planned for a future release.

3a in place of 3*a is another controversial issue. Clearly we cannot do it with numbers, because 32 is not the same a 3*2. There are also problems with hex numbers: 0x1 is 1, but could mean 0*x1. It is hard to tell what you want with 20x1. It can be 2*0x1 or 20*x1. Also 0x1a could mean 0x1*a or the number 26 written in hex. We can forbid hex numbers from this shorthand, and variable names starting with x, but it makes the syntax to be remembered more complex.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: hmm
PostPosted: July 4th, 2008, 8:07 am 
Offline

Joined: June 21st, 2007, 10:10 pm
Posts: 41
Location: 43.074233,-72.424707
it seems to be a sound and useful script, however, I think a simple patch to the ahk source code (allowing recursive expressions) would be much easier to use.
for example:
Code:
x = 2
y = 4
var := "x + 3y"
ans := %var% (which logically is equivalent to ans := x + 3y)

currently, a derefed variable in an expression is always considered by ahk to be the name of another variable, not part of the expression, which would allow continued support for dynamic variable and partially dynamic variables while introducing expression compatibility.

_________________
problems := bugs + errors + glitches
(problems != 0) ? code := debug(code) : celebrate()
--
humor for: 1. Programmers 2. Everyone


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2008, 8:10 am 
Offline

Joined: June 21st, 2007, 10:10 pm
Posts: 41
Location: 43.074233,-72.424707
Salkin wrote:
* another thing would be the automatic multiplication. for example 3a should be the same as 3*a, or 3pi the same as 3*pi.


the reason this wont work is because there would be no way for the script to tell the difference between the multiplication and another variable name. 3 * pi would be 3pi, which is a valid name. also a * pi would be api, another valid name.

_________________
problems := bugs + errors + glitches
(problems != 0) ? code := debug(code) : celebrate()
--
humor for: 1. Programmers 2. Everyone


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 81 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], Exabot [Bot], Stigg and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group