- NSIS Discussion
- Math::Script: Another huge, undocumented, bug-full, but "might be useful" plugin.
Archive: Math::Script: Another huge, undocumented, bug-full, but "might be useful" plugin.
brainsucker
1st September 2003 01:20 UTC
Math::Script: Another huge, undocumented, bug-full, but "might be useful" plugin.
First. Afrow UK: Sorrrrryyyy :) I've got some free time and spent it on math instead of tray icon... No mercy to me, I know...
To the topic. It's unfinished. No floating-point functions like sin, cos etc, but it's usable for testing.
ToDo:
1. push / pop
2. arrays
3. functions:
a) floating point
b) type conversions
c) user defined
Copy math.zip\plugin\math.dll to your plugins folder and see math.zip\math.nsi as example.
here comes math.txt:
C-like style scripting (operators at least).
Tip: plugin watches the case of the letters.
How to use it? Simple:
Strcpy $0 "Brainsucker"
Math::Script "a = 'Math'; B = 'Script'; r0 += ' wants to use ' + a + '::' + b +'!'"
DetailPrint "$0"
That string will fill r0 with some shit.
Here are some other samples:
10! (factorial, r0 will contain '10! = 362880'):
r0 = '10! = ' + (1*2*3*4*5*6*7*8*9)
the same:
a = b = 1; {++a <= 10, b = b*a}; r0 = (a-1) + '! = ' + b
Some floating point:
Strcpy $R0 "1e1"
Math::Script "pi = 3.14159; R1 = 2*pi*R0; r0 = 'Length of circle with radius ' + R0 + ' is equal to ' + R1 + '.'"
Detailprint "$0"
Ok. Variables.
NSIS: r0-r9 -> $0-$9. R0-R9 -> $R0-$R9.
Also CMDLINE, INSTDIR, OUTDIR, LANG, EXEDIR.
User definable: name starting from character, up to 28 letters long.
Supported types: int (in fact that is __int64), float (double in fact),
string.
Int: just numbers, may include sign.
Float: -123.456, 123.456e-78, 123e-45
String: something in quotes ("", '', ``).
Operators (some binary, some unary):
>>= <<= -= += /= *= |= &= ^= %= -- ++ >> << && || <= =< >= => != ==
-> <- = + - * / % < > & | ^ ~ !
Only some are applicable to float (logic & arithmetic) and string (+ and logic)
of course.
Script is set of expressions (mathematical in general) delimeted with ';'.
Processing is not mathematicaly right (2+2*2 will give 8, not 6), so use round
brakes (for ex: 2+(2*2) ).
Flow control:
if-then-else like: [if-expression, then-expr, else-expr]
example:
[a==0, b=1; c=2, b *= (--c); c/=10]
C eq:
if (a==0) { b=1; c=2;} else { b*=(c++);c-=10; }
while (expr) do; like {expr, do}
example:
{(c<1.1e25)&&(b < 10), b++; c*=1.23}
C eq:
while ((c<1.1e25)&&(b<10)) { b++; c*=1.23; }
All the shit (like variables) will be saved between calls if you'll use
/NOUNLOAD or setpluginunload alwaysoff.
brainsucker
1st September 2003 01:31 UTC
Heh. Forgotten the main.
HAPPY NEW ... AUTUMN! :)
P.S. todo.4. Float-to-string formatting.
brainsucker
2nd September 2003 01:17 UTC
Now Interactive Math Tester included. Just run Mathtest.exe from archive and test your own expression or one from 5 sample expressions with one mouse click :)
Update: Floating point, type conversion, and float formatting functions are added. Almost all CRT math functions present.
Documentation (if it is possible to call THAT thing so) updated a bit.
kichik
2nd September 2003 08:31 UTC
Cool plug-in. Let me know when you've finished adding all that you wanted.
deguix
5th September 2003 21:09 UTC
Maybe you based in the function "Mathematical Operation" (old "Advanced Integer Operation"). Try to add these things too:
- Support for thousand... comma separation (i.e. $1,000,000.00 as in U.S.A.).
- Support for comma as decimal separator, and thousand... dot separator (i.e. $1.000.000,00 - as in Brazil).
- Predefined functions (i.e. retangle perimeter R=a+b+c+d).
- Absolute Value (i.e. |4-12| is 8).
- Matrix (i.e. [1;5;2;4]+[6;2;9;12] is [7;7;11;16]).
- nPr - Permutation.
- nCr - Combination.
- % - Percentage (i.e. 8% is 0.08).
- E - Exponent (i.e. 2E is 100)
- Root (i.e. root(9) is 3)
...
And a question, when you do 1 / 3 what is the result given by the dll? (I cannot open zip files, use NSIS...)
brainsucker
5th September 2003 21:36 UTC
1. since the plugin should be small enough in size i'll leave all rarely used functions for scripting. commas for example.
3. it will have user definable functions. I'm working on it now, all other things are done.
4. fabs()
5. for now it will have no support for matrix operation, but matrix is actually an array, and you could write user function to summarize two arrays.
6. 7. I should look to the dictionary ;)
8. *0.01 actually. unneccesary.
all standart mathematical functions are present.
brainsucker
6th September 2003 04:50 UTC
pre-final. Almost all done.
try this at mathtest.exe:
ar{"I","like","NSIS"}; s=""; i=0; {i<3, s+=ar[i++]+" "}; r0=s
or this (this is one script):
rec(a)([a>1,rec(a-1)*a,1.0])
r0 = rec(100)
kichik
21st September 2003 16:36 UTC
Still think it's "bug-full"? Should it be released along with NSIS 2.0b4? Any chance you'll get a couple of free minutes to update the docs to HTML (using MUI's readme style)?
Joost Verburg
21st September 2003 16:38 UTC
HTML documentation in my Modern UI/InstallOptions style for System/Math would be very useful. The current text files are quite difficult tot read. The whole template is ready, you just have to convert 'em.
brainsucker
21st September 2003 21:41 UTC
Kichik: just kidding :) 1. I've just fixed some of them. 2. currently I don't know any more bugs 3. I know no required features :)
Joost: Ok... I'll see what can I do.. Anyway, the Docs-writing is not my primary talent/skill :)
1. Unary-Pre operators detection fixed.
2. Unary Minus operator added (now legal, worked before?).
3. GetReference operator (&). For example (a=&b; *a=3;) will set b=3.
4. Operators precedence added (C-like), much more intellectual expressions parsing.
5. Functions redefenition added, use "#name", like "func()(1); #func()(2);".
Joost Verburg
21st September 2003 21:43 UTC
Saying it's undocumented and bugfull at the beginning of the documentation is not such a good idea :)
Nice HTML style documentation would make it way easier to use.
brainsucker
21st September 2003 21:48 UTC
MathTest executable. And another example, ascending bubble sort of array (all items types are accepted), use BubbleSort(ARRAY, SIZE).
Math::Script /NOUNLOAD "BubbleSort(a,c, i,k,t) (i=1; #{i, i=k=0; #{++k<c, #[a[k]<a[k-1],t=a[k-1];a[k-1]=a[k];a[k]=t;i++]}})"