| View previous topic :: View next topic |
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 3644 Location: Belgrade
|
Posted: Wed Apr 04, 2007 10:26 am Post subject: |
|
|
I like the name too : _________________
 |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4065 Location: Pittsburgh
|
Posted: Wed Apr 25, 2007 3:00 pm Post subject: |
|
|
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! |
|
| Back to top |
|
 |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Tue Oct 30, 2007 10:53 pm Post subject: |
|
|
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
} |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4065 Location: Pittsburgh
|
Posted: Wed Oct 31, 2007 12:43 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Gerf Guest
|
Posted: Fri Mar 07, 2008 8:37 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4065 Location: Pittsburgh
|
Posted: Fri Mar 07, 2008 9:05 pm Post subject: |
|
|
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". |
|
| Back to top |
|
 |
Gerf Guest
|
Posted: Fri Mar 07, 2008 9:53 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1718
|
Posted: Sat May 24, 2008 8:09 am Post subject: |
|
|
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 _________________
 |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4065 Location: Pittsburgh
|
Posted: Sat May 24, 2008 7:36 pm Post subject: |
|
|
| 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.) |
|
| Back to top |
|
 |
Rajat
Joined: 28 Mar 2004 Posts: 1718
|
Posted: Sat May 24, 2008 9:56 pm Post subject: |
|
|
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.  _________________
 |
|
| Back to top |
|
 |
Salkin Guest
|
Posted: Tue May 27, 2008 3:13 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Rajat as guest Guest
|
Posted: Tue May 27, 2008 3:27 pm Post subject: |
|
|
| Squaring is simple. 3**2 (3 to the power 2) gives 9 |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4065 Location: Pittsburgh
|
Posted: Tue May 27, 2008 3:44 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
apocalypse~r
Joined: 21 Jun 2007 Posts: 23
|
Posted: Fri Jul 04, 2008 7:07 am Post subject: hmm |
|
|
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
code := (problems != 0) ? debug(code) : celebrate() |
|
| Back to top |
|
 |
apocalypse~r
Joined: 21 Jun 2007 Posts: 23
|
Posted: Fri Jul 04, 2008 7:10 am Post subject: |
|
|
| 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
code := (problems != 0) ? debug(code) : celebrate() |
|
| Back to top |
|
 |
|