Math plug-in: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
mNo edit summary |
|||
| (12 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{p-author|deguix}} | |||
''This plug-in is included in the NSIS distribution package.'' | |||
== Description == | == Description == | ||
This is | This plug-in is used to calculate in-line mathematical expressions. | ||
== Plug-in functions == | |||
=== Math::Script === | |||
== | ==== Syntaxes ==== | ||
;Calling Syntax | |||
:<highlight-nsis>Math::Script "MathExpression"</highlight-nsis> | |||
;Returning Syntax | |||
:''None'' | |||
==== Description ==== | |||
Executes a mathematical expression specified in the ''MathExpression'' parameter. | |||
==== Parameters ==== | |||
;''MathExpression'' | |||
:Specifies the expression to be executed. More details on the parameter syntax can be found in the readme (comes with the plug-in). | |||
:<font color=red>'''WARNING:'''</font> Any mathematical expression syntax errors create GPF errors. | |||
== Contributions == | |||
=== Math expression functions (mostly by [[User:deguix|deguix]]) === | |||
This is the file that I had in my computer with all the functions that I made for the [[Math plug-in]]. I didn't have enough time to make a documentation for and to arrange those functions below. You're welcome to add a description of use for any function here. | |||
<pre> | <pre> | ||
| Line 10: | Line 41: | ||
MatAdd(a,b) (c=-1; x={}; d=#[l(a)>l(b), l(a), l(b)]; #{c++<d, x[c]=a[c]+b[c]}; x) | MatAdd(a,b) (c=-1; x={}; d=#[l(a)>l(b), l(a), l(b)]; #{c++<d, x[c]=a[c]+b[c]}; x) | ||
MatSub(a,b) (c=-1; x={}; d=#[l(a)>l(b), l(a), l(b)]; #{c++<d, x[c]=a[c]-b[c]}; x) | MatSub(a,b) (c=-1; x={}; d=#[l(a)>l(b), l(a), l(b)]; #{c++<d, x[c]=a[c]-b[c]}; x) | ||
;Math Constants | ;Math Constants | ||
pi = 4*atn(1) | |||
pi = 3.14159 | pi = 3.14159 | ||
é = 2.71828 | |||
gamma = 0.57721 | |||
;Math Formulas | ;Math Formulas | ||
Factorial - fac(a, b,c,d) (#[a<0, a*=-1; d=1, d=0]; b=c=1; #{++b<=a, c=c*b}; #[d==1, c*=-1]; d=0; c) | Factorial - fac(a, b,c,d) (#[a<0, a*=-1; d=1, d=0]; b=c=1; #{++b<=a, c=c*b}; #[d==1, c*=-1]; d=0; c) | ||
Permutation - npr(a, b) (S=c; c=1; #{++b<=a, c=c*b}; a=c; c=S;a) | Permutation without repetition - npr(a, b) (S=c; c=1; #{++b<=a, c=c*b}; a=c; c=S;a) | ||
Combination - ncr(a, b) (S=d; S=c; d=b; c=1; #{b++<=a, c=c*(b-1)}; a=b=1; #{a++<=d, b=b*(a-1)}; a=c/b; c=S; d=S; a) | Combination without repetition - ncr(a, b) (S=d; S=c; d=b; c=1; #{b++<=a, c=c*(b-1)}; a=b=1; #{a++<=d, b=b*(a-1)}; a=c/b; c=S; d=S; a) | ||
type (a, v) (#[a == 0, #[a == c(0), v = "array", v = "nil/zero"], #[a/0.0 == a, v = "string", #[a==flr(a), v="integer", v = "float"]]];v) | |||
Detects the type of the variable: | |||
- zeronull: zeronull == "0" && zeronull == c(48) ---> number "0" character | |||
- array: array == "0" && array == c(0) ---> null character | |||
- string: string/0.0 == string | |||
- number: number/0.0 == "#INF" | |||
- integer: integer==flr(integer) | |||
- float: float!=flr(float) | |||
- Math bug: 0.0/0.0 yields 0. It should be 1. | |||
Absolute Value (fixed) - abv(a) (#[a < 0, a *= -1, a]) | Absolute Value (fixed) - abv(a) (#[a < 0, a *= -1, a]) | ||
Power (fixed) - | Power (fixed) - power(a,b, c) (c=1;#{b-->0,c=c*a};c) | ||
Root (fixed) - root(a,n,p, x,xt,pt) (x=1;xt=pt=-1;#{pow(x,n)!=a&&#[p!=-1,++pt<=p,1]&&x!=xt,xt=x;x=((n-1)*x+(a/pow(x,n-1.0)))/n};x) | |||
Sign - sgn(a) (#[a < 0, a = -1, #[a > 0, a = 1, a = 0]]) | Sign - sgn(a) (#[a < 0, a = -1, #[a > 0, a = 1, a = 0]]) | ||
Signum (alternative) - sgn(a) (a/abv(a)) | |||
Fractional Part - fra(a, b) (b=a; a=b-flr(a)) | Fractional Part - fra(a, b) (b=a; a=b-flr(a)) | ||
Integer Part - int(a) (flr(a)) | Integer Part - int(a) (flr(a)) | ||
| Line 46: | Line 91: | ||
DayToSec(a) (a*HourToSec(24)) | DayToSec(a) (a*HourToSec(24)) | ||
MonthToSec(a,b, c) (a--;c=a*DayToSec(31);#[a>=1,#[IsLeapYear(b)==1,c-=DayToSec(2),c-=DayToSec(3)]];#[a>=3, c-=DayToSec(1)];#[a>=5, c-=DayToSec(1)];#[a>=8, c-=DayToSec(1)];#[a>=10, c-=DayToSec(1)];#[a>11, c=0];c) | MonthToSec(a,b, c) (a--;c=a*DayToSec(31);#[a>=1,#[IsLeapYear(b)==1,c-=DayToSec(2),c-=DayToSec(3)]];#[a>=3, c-=DayToSec(1)];#[a>=5, c-=DayToSec(1)];#[a>=8, c-=DayToSec(1)];#[a>=10, c-=DayToSec(1)];#[a>11, c=0];c) | ||
YearToSec(a,b, c) (c=0;#{++b<=a,#[IsLeapYear( | YearToSec(a,b, c) (c=0;#{++b<=a,#[IsLeapYear(b-1),c+=DayToSec(366),c+=DayToSec(365)]};c) | ||
DateToSec(a,b,c,d,e,f,g, h) (h=YearToSec(g, a)+MonthToSec(f, a)+DayToSec(e-1)+HourToSec(b)+MinToSec(c)+d;h) | DateToSec(a,b,c,d,e,f,g, h) (h=YearToSec(g, a)+MonthToSec(f, a)+DayToSec(e-1)+HourToSec(b)+MinToSec(c)+d;h) | ||
;Format: DateToSec(Year in which the counting of seconds start,Hour,Minute,Second,Day,Month,Year) | |||
r0=DateToSec(2004,0,0,0,1,1,2004) | r0=DateToSec(2004,0,0,0,1,1,2004) | ||
| Line 60: | Line 106: | ||
SecToDate(a,b,&c,&d,&e,&f,&g,&h, i) (*h=SecToYear(a,b,i);a=i;*g=SecToMonth(a,b,i);a=i;*f=SecToDay(a,i)+1;a=i;*c=SecToHour(a,i);a=i;*d=SecToMin(a,*e)) | SecToDate(a,b,&c,&d,&e,&f,&g,&h, i) (*h=SecToYear(a,b,i);a=i;*g=SecToMonth(a,b,i);a=i;*f=SecToDay(a,i)+1;a=i;*c=SecToHour(a,i);a=i;*d=SecToMin(a,*e)) | ||
;Format: SecToDate(Seconds,Year in which the counting of seconds start,Hour,Minute,Second,Day,Month,Year) | |||
SecToDate(5184000,2004,r0,r1,r2,r3,r4,r5) | SecToDate(5184000,2004,r0,r1,r2,r3,r4,r5) | ||
| Line 361: | Line 408: | ||
ArrayCopy(a, a2,n,nt,t) (a2 = {};n=0;nt=ArrayLength(a);#{n<nt, ArrayInsert(a2,a[n],n);n++};a2) | ArrayCopy(a, a2,n,nt,t) (a2 = {};n=0;nt=ArrayLength(a);#{n<nt, ArrayInsert(a2,a[n],n);n++};a2) | ||
ArrayCrop(a,n,nt, i) (i=n;#{n<nt, ArrayRemove(a,i);n++};a) | ArrayCrop(a,n,nt, i) (i=n;#{n<nt, ArrayRemove(a,i);n++};a) | ||
ArrayItemGet(a,i,it ,a2,itmp,nt) (a2={};itmp=nt=-1;#[it==0,#[l(a)+i>=0&&i<l(a),#[i>=0,itmp=a[i],itmp=a[l(a)+i]],'IndexError'],#[it==1,#{++nt<2-1,#[i[nt]<0,i[nt]=l(a)+i[nt]]};nt=-1;itmp=i[0]-1;#{++nt;++itmp<=i[1]-1,#[itmp<l(a),a2[nt]=a[itmp];a2]};a2,#[it==2,#{++nt;nt<=l(i)-1,#[l(a)+i[nt]>=0&&i[nt]<l(a),++itmp;#[i[nt]>=0,a2[itmp]=a[i[nt]],a2[itmp]=a[l(a)+i[nt]]];a2]};a2,'ValueError']]]) | |||
ArrayToString(a,sep, n,nt,t) (n=-1;t="";nt=ArrayLength(a);#{++n<nt, t=t+a[n]+sep};t=t[0,-l(sep)-1];t) | ArrayToString(a,sep, n,nt,t) (n=-1;t="";nt=ArrayLength(a);#{++n<nt, t=t+a[n]+sep};t=t[0,-l(sep)-1];t) | ||
| Line 407: | Line 456: | ||
Couldn't finish HLSToRGB to accuratelly output consistant results. There is always results in the range 1+/-.</pre> | Couldn't finish HLSToRGB to accuratelly output consistant results. There is always results in the range 1+/-.</pre> | ||
[[Category: | {{p-infobox/start|Contribution details}} | ||
{{p-infobox/start|General information}} | |||
{|width=100% | |||
|width=20% | Author: | |||
|width=80% | [[User:brainsucker|brainsucker]] | |||
|- | |||
|width=20% | Version (Last updated): | |||
|width=80% | 24/Nov/2005 | |||
|- | |||
|width=20% | Category: | |||
|width=80% | [[Category:Plugins]][[:Category:Plugins|Plug-ins]] | |||
|- | |||
|width=20% | Supported Operating System: | |||
|width=80% | Windows (All) | |||
|} | |||
{{p-infobox/end}} | |||
{{p-infobox/start|Development information}} | |||
{|width=100% | |||
|width=20% | Administrators: | |||
|width=80% | [[User:brainsucker|brainsucker]] | |||
|- | |||
|width=20% | Development Status: | |||
|width=80% | Mature | |||
|- | |||
|width=20% | License: | |||
|width=80% | zlib/libpng license | |||
|- | |||
|width=20% | Programming/Scripting Languages: | |||
|width=80% | C, C++ | |||
|} | |||
{{p-infobox/end}} | |||
{{p-infobox/end}} | |||
{{ | {{p-infobox/start|Page maintenance notes}} | ||
{|width=100% | |||
{{pm-cleanup}} | |||
|- | |||
{{pm-attention}} | |||
|} | |||
{{p-infobox/end}} | |||
Latest revision as of 15:16, 5 March 2010
| Author: deguix (talk, contrib) |
This plug-in is included in the NSIS distribution package.
Description
This plug-in is used to calculate in-line mathematical expressions.
Plug-in functions
Math::Script
Syntaxes
- Calling Syntax
Math::Script "MathExpression"
- Returning Syntax
- None
Description
Executes a mathematical expression specified in the MathExpression parameter.
Parameters
- MathExpression
- Specifies the expression to be executed. More details on the parameter syntax can be found in the readme (comes with the plug-in).
- WARNING: Any mathematical expression syntax errors create GPF errors.
Contributions
Math expression functions (mostly by deguix)
This is the file that I had in my computer with all the functions that I made for the Math plug-in. I didn't have enough time to make a documentation for and to arrange those functions below. You're welcome to add a description of use for any function here.
;Matrices
MatAdd(a,b) (c=-1; x={}; d=#[l(a)>l(b), l(a), l(b)]; #{c++<d, x[c]=a[c]+b[c]}; x)
MatSub(a,b) (c=-1; x={}; d=#[l(a)>l(b), l(a), l(b)]; #{c++<d, x[c]=a[c]-b[c]}; x)
;Math Constants
pi = 4*atn(1)
pi = 3.14159
é = 2.71828
gamma = 0.57721
;Math Formulas
Factorial - fac(a, b,c,d) (#[a<0, a*=-1; d=1, d=0]; b=c=1; #{++b<=a, c=c*b}; #[d==1, c*=-1]; d=0; c)
Permutation without repetition - npr(a, b) (S=c; c=1; #{++b<=a, c=c*b}; a=c; c=S;a)
Combination without repetition - ncr(a, b) (S=d; S=c; d=b; c=1; #{b++<=a, c=c*(b-1)}; a=b=1; #{a++<=d, b=b*(a-1)}; a=c/b; c=S; d=S; a)
type (a, v) (#[a == 0, #[a == c(0), v = "array", v = "nil/zero"], #[a/0.0 == a, v = "string", #[a==flr(a), v="integer", v = "float"]]];v)
Detects the type of the variable:
- zeronull: zeronull == "0" && zeronull == c(48) ---> number "0" character
- array: array == "0" && array == c(0) ---> null character
- string: string/0.0 == string
- number: number/0.0 == "#INF"
- integer: integer==flr(integer)
- float: float!=flr(float)
- Math bug: 0.0/0.0 yields 0. It should be 1.
Absolute Value (fixed) - abv(a) (#[a < 0, a *= -1, a])
Power (fixed) - power(a,b, c) (c=1;#{b-->0,c=c*a};c)
Root (fixed) - root(a,n,p, x,xt,pt) (x=1;xt=pt=-1;#{pow(x,n)!=a&&#[p!=-1,++pt<=p,1]&&x!=xt,xt=x;x=((n-1)*x+(a/pow(x,n-1.0)))/n};x)
Sign - sgn(a) (#[a < 0, a = -1, #[a > 0, a = 1, a = 0]])
Signum (alternative) - sgn(a) (a/abv(a))
Fractional Part - fra(a, b) (b=a; a=b-flr(a))
Integer Part - int(a) (flr(a))
Reciprocal - rcp(a) (1/a)
Arithmetic Average - avg(a,b) ((a+b)/2)
Geometric Average - gav(a,b) (sqr(a*b))
Harmonic Average - hav(a,b) (2/(1/a+1/b))
Prime Numbers - PN(f,t, m,a,b,c,n,i,d,k) (m=sqt(t)+1;a={};b={};c=n=0; i=2; #{i<t, d=k=0; #{(!k)&&(d<n), #[i%(a[d++])==0, k++]}; #[!k,#[i>=f,b[c++]=i];#[i<=m,a[n++]=i,#[i<f,i=f-1]]]; i++}; b)
;Date & Time
IsLeapYear(a, b,c) (#[mdf(a/4.0,c) == 0, #[mdf(a/100.0,c) > 0, b = 1, #[mdf(a/400.0,c) == 0, b = 1, b = 0]],b = 0];b)
MinToSec(a) (a*60)
HourToSec(a) (a*MinToSec(60))
DayToSec(a) (a*HourToSec(24))
MonthToSec(a,b, c) (a--;c=a*DayToSec(31);#[a>=1,#[IsLeapYear(b)==1,c-=DayToSec(2),c-=DayToSec(3)]];#[a>=3, c-=DayToSec(1)];#[a>=5, c-=DayToSec(1)];#[a>=8, c-=DayToSec(1)];#[a>=10, c-=DayToSec(1)];#[a>11, c=0];c)
YearToSec(a,b, c) (c=0;#{++b<=a,#[IsLeapYear(b-1),c+=DayToSec(366),c+=DayToSec(365)]};c)
DateToSec(a,b,c,d,e,f,g, h) (h=YearToSec(g, a)+MonthToSec(f, a)+DayToSec(e-1)+HourToSec(b)+MinToSec(c)+d;h)
;Format: DateToSec(Year in which the counting of seconds start,Hour,Minute,Second,Day,Month,Year)
r0=DateToSec(2004,0,0,0,1,1,2004)
SecToYear(a,b,&c, d) (d=b;#{*c=#[IsLeapYear(d),DayToSec(366),DayToSec(365)];a>=*c,a-=*c;d++};*c=a;d)
SecToMonth(a,b,&c, d,e) (d=0; e={31,28,31,30,31,30,31,31,30,31,30,31,0};#{#[d>=12,*c=a+1;d=-1,*c=e[d]*DayToSec(1)];#[(d==1)&&(IsLeapYear(b)),*c+=DayToSec(1)];a>=*c,a-=*c;d++};*c=a;++d)
SecToDay(a,&b) (*b=a%DayToSec(1); a=a/DayToSec(1))
SecToHour(a,&b) (*b=a%HourToSec(1); a=a/HourToSec(1))
SecToMin(a,&b) (*b=a%MinToSec(1); a=a/MinToSec(1))
SecToDate(a,b,&c,&d,&e,&f,&g,&h, i) (*h=SecToYear(a,b,i);a=i;*g=SecToMonth(a,b,i);a=i;*f=SecToDay(a,i)+1;a=i;*c=SecToHour(a,i);a=i;*d=SecToMin(a,*e))
;Format: SecToDate(Seconds,Year in which the counting of seconds start,Hour,Minute,Second,Day,Month,Year)
SecToDate(5184000,2004,r0,r1,r2,r3,r4,r5)
;Number Types
abv(a) (#[a < 0, a *= -1, a])
poe(a,b, c) (c=1;#{b-->0,c=c*a};c)
Dec2Hex(a,b, c,d,s,hex) (#[a<0,a=poe(16,b)+a];r2=a;hex={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};s='';#{b-->0,s=hex[a%16]+s; a=a/16};s)
r0 = Dec2Hex(-1,2)
;Strings
Sort_Bubble(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++]}})
StrLoc(s,e, p,i) (p=-1;i=0;#{(i<l(s))&&(p<0),#[s[i,i+l(e)-1]==e,p=i];i++};p)
StrRep(s,fa,ra, i,f,r,e,p) (i=0;#{i<l(fa),e=l(f=fa[i]);r=ra[i];p=0;#{p<l(s),#[s[p,p+e-1]==f,s=(s[,p-1])+r+(s[p+e,]);p+=l(r),p++]};i++};s)
;Geometric Figures
AreaSquare(s,A, t,c) (#[s!=0,c|=0x1];#[A!=0,c|=0x2]; #[c==0x1, t=s*s,#[c==0x2, t=sqt(A),#[c==0x3, #[s*s==A, t=1, t=0],t='error']]];t)
AreaRectangle(b,h,A, t,c) (#[b!=0,c|=0x1];#[h!=0,c|=0x2];#[A!=0,c|=0x4]; #[c==0x3, t=b*h,#[c==0x5, t=A/b,#[c==0x6, t=A/h,#[c==0x7, #[b*h==A, t=1, t=0], t='error']]]];t)
AreaParallelogram(b,h,A, t,c) (#[b!=0,c|=0x1];#[h!=0,c|=0x2];#[A!=0,c|=0x4]; #[c==0x3, t=b*h,#[c==0x5, t=A/b,#[c==0x6, t=A/h,#[c==0x7, #[b*h==A, t=1, t=0], t='error']]]];t)
AreaTriangle(b,h,A, t,c) (#[b!=0,c|=0x1];#[h!=0,c|=0x2];#[A!=0,c|=0x4]; #[c==0x3, t=(1/2)*(b*h),#[c==0x5, t=A/(b/2),#[c==0x6, t=A/(h/2),#[c==0x7, #[(1/2)*(b*h)==A, t=1, t=0], t='error']]]];t)
AreaRhombus(d1,d2,A, t,c) (#[d1!=0,c|=0x1];#[d2!=0,c|=0x2];#[A!=0,c|=0x4]; #[c==0x3, t=(d1*d2)/2,#[c==0x5, t=A/(d1/2),#[c==0x6, t=A/(d2/2),#[c==0x7, #[(d1*d2)/2==A, t=1, t=0], t='error']]]];t)
AreaRegPolygon(a,p,A, t,c) (#[a!=0,c|=0x1];#[p!=0,c|=0x2];#[A!=0,c|=0x4]; #[c==0x3, t=(a*p)/2,#[c==0x5, t=A/(a/2),#[c==0x6, t=A/(p/2),#[c==0x7, #[(a*p)/2==A, t=1, t=0], t='error']]]];t)
AreaCircle(r,A, t,c) (#[r!=0,c|=0x1];#[A!=0,c|=0x2]; #[c==0x1, t=r*r*pi,#[c==0x2, t=sqt(A/pi),#[c==0x3, #[r*r*pi==A, t=1, t=0],t='error']]];t)
PythagorianTheorem(a,b,c, t,d) (#[a!=0,d|=0x1];#[b!=0,d|=0x2];#[c!=0,d|=0x4]; #[d==0x3, t=sqt((a*a)+(b*b)),#[d==0x5, t=sqt((c*c)-(a*a)),#[d==0x6, t=sqt((c*c)-(b*b)),#[d==0x7, #[(a*a)+(b*b)==(c*c), t=1, t=0], t='error']]]];t)
CPythagorianTheorem(a,b,c, t,d) (#[a!=0,d|=0x1];#[b!=0,d|=0x2];#[c!=0,d|=0x4]; #[d==0x3, t=sqt((a*a)+(b*b)),#[d==0x5, t=sqt((c*c)-(a*a)),#[d==0x6, t=sqt((c*c)-(b*b)),#[d==0x7, #[(a*a)+(b*b)>(c*c), t=1, #[(a*a)+(b*b)<(c*c), t=2, t=0]], t='error']]]];t)
mtsTQ(s) (s = s(NS); #[s[0]=='$\"',s=s[1,]]; #[s[-1]=='$\"',s=s[,-2]]; NS = s)
mtsDL(s) (s=s(NS); p=StrLoc(s,'\r\n'); #[p>=0, (NS=s[p+4,]; NS=#[p>0,s[,p-1],'']), (NS='';NS=s)])
;Array
ArrayInsert(a,s,i, n,nf,nt,s2,t) (t='error'; #[s!='',n=-1;nf=0;s2=0;nt=ArrayLength(a)+1;#{n++<nt,#[n>=i, #[n==i, t=1];#[nf%2==0,#[n!=nt,s2=a[n]];a[n]=s];#[nf%2==1,#[n!=nt,s=a[n]];a[n]=s2];++nf]}];#[t=='error', error='ValueError'];t)
# 1:
Test = {"A", "B"}
ArrayInsert(Test, "C", 2)
r0 = Test[2]
# Result: 1
- Test = {"A","B","C"}
# 2:
Test = {"A", "B"}
ArrayInsert(Test, "C")
r0 = Test[2]
# Result: 1
- Test = {"C","A","B"}
# Error 1:
Test = {"A", "B"}
r0 = ArrayInsert(Test)
# Result: "error"
- Test = {"A", "B"}
- error = "ValueError"
ArrayAppend(a,s) (t=ArrayInsert(a,s,ArrayLength(a));t)
# 1:
Test = {"A", "B"}
r0 = ArrayAppend(Test, "C")
# Result: 1
- Test = {"A", "B", "C"}
# Error 1:
Test = {"A", "B"}
r0 = ArrayAppend(Test)
# Result: "error"
- Test = {"A", "B"}
- error = "ValueError"
ArrayCount(a,s, n,nt,t) (t='error';#[s!=0,n=-1;t=0;nt=ArrayLength(a);#{++n<nt, #[a[n]==s, ++t]}, t=ArrayLength(a)];t)
# 1:
Test = {"A", "B", "C", "A"}
r0 = ArrayCount(Test, "A")
# Result: 2
- Test = {"A", "B", "C", "A"}
# 2:
Test = {"A", "B", "C", "A"}
r0 = ArrayCount(Test)
# Result: 4
- Test = {"A", "B", "C", "A"}
ArrayRemove(a,i, n,nf,nt,s,s2,t) (t='error';#[i>=0,n=-1;nf=0;s=s2=0;nt=ArrayLength(a);#{nt-->n,#[nt>=i, #[nt==i, t=a[i]];#[nf%2==0,#[nt!=n,s2=a[nt]];a[nt]=s];#[nf%2==1,#[nt!=n,s=a[nt]];a[nt]=s2];++nf]}];#[t=='error', error='IndexError'];t)
# 1:
Test = {"A", "B", "C"}
r0 = ArrayRemove(Test, 2)
# Result: "C"
- Test = {"A", "B"}
# 2:
Test = {"A", "B", "C"}
r0 = ArrayRemove(Test)
# Result: "A"
- Test = {"B", "C"}
# Error 1 (Needs to be fixed):
Test = {"A", "B", "C"}
r0 = ArrayRemove(Test, -1)
# Result: "error"
- Test = {"A", "B", "C"}
- error = "IndexError"
ArrayPop(a) (t=ArrayRemove(a,ArrayLength(a)-1);t)
# 1:
Test = {"A", "B", "C"}
r0 = Pop(Test)
# Result: "C"
- Test = {"A", "B"}
ArrayRemoveRepeated(a,s, n,nt,t,f) (#[s==0, f=1];n=-1;nt=ArrayLength(a);t='error';#{#[f==1, s=a[n+1];++n<nt && ArrayCount(a,s)>1,Count(a,s)>1], ArrayRemove(a, ArrayIndex(a,s,2)); t=1};#[t=='error', error='ValueError'];t)
# 1:
Test = {"A", "B", "C", "A", "B", "C"}
ArrayRemoveRepeated(Test, "A")
# Result: 1
- Test = {"A", "B", "C", "B", "C"}
# 2:
Test = {"A", "B", "C", "A", "B", "C"}
ArrayRemoveRepeated(Test)
# Result: 1
- Test = {"A", "B", "C"}
ArrayRemoveItem(a,s,it, i,n,nt,t) (t='error';#[s!="" && i>=0, n=-1;nt=ArrayCount(a,s);i=0;#{++n<=nt, #[a[s]==s, #[i>=it; t=ArrayRemove(a,n)}];#[t!='error',t=1];t)
# 1:
Test = {"A", "B", "C"}
r0 = ArrayRemoveItem(Test, "C")
# Result: 2
- Test = {"A", "B", "C"}
# Error:
// NEEDS VERIFICATION
ArrayIndex(a,s,it, f,i,n,nt,t) (t='error';#[s!='',n=-1;nt=ArrayLength(a); i=0;f=0; #[it<0, n=nt;nt=-1;it*=-1;f=1];#[it==0, it=1];#{#[f==1, --n>nt,++n<nt] && i<it, #[a[n]==s, ++i]};#[i>=it, #[f==1, t=++n, t=--n]]];#[t=='error' && s=='',error='ValueError', #[t=='error', error='IndexError']];t)
# 1:
Test = {"A", "B", "C"}
r0 = ArrayIndex(Test, "C")
# Result: 2
- Test = {"A", "B", "C"}
# 2:
Test = {"A", "B", "C", "A"}
r0 = ArrayIndex(Test, "A", 2)
# Result: 3
- Test = {"A", "B", "C", "A"}
# 3:
Test = {"A", "B", "C", "A"}
r0 = ArrayIndex(Test, "A", -2)
# Result: 0
- Test = {"A", "B", "C", "A"}
# Error 1:
Test = {"A", "B", "C"}
r0 = ArrayIndex(Test)
# Result: "error"
- Test = {"A", "B", "C"}
- error = "ValueError"
# Error 2:
Test = {"A", "B", "C", "A"}
r0 = ArrayIndex(Test, "A", 3)
# Result: 0
- Test = {"A", "B", "C", "A"}
- error = "IndexError"
ArraySwap(a,i,i2, s,s2,t) (t='error';#[i==i2,t=1];#[i2>i,s=i;i=i2;i2=s];s=ArrayRemove(a,i);s2=ArrayRemove(a,i2);i2=ArrayInsert(a,s,i2);i=ArrayInsert(a,s2,i);#[i!='error' && i2!='error' && s!='error' && s2!='error',t=1];#[t=='error', error='ValueError'];t)
# 1:
Test = {"A", "B", "C"}
r0 = ArraySwap(Test, 0, 2)
# Result: 1
- Test = {"C", "B", "A"}
# 2:
Test = {"A", "B", "C"}
r0 = ArraySwap(Test, 2)
# Result: 1
- Test = {"C", "B", "A"}
# 3:
Test = {"A", "B", "C"}
r0 = ArraySwap(Test)
# Result: 1
- Test = {"A", "B", "C"}
# Error 1:
Test = {"A", "B", "C"}
r0 = ArraySwap(Test, -2, 0)
# Result: 0
- Test = {"A", "B", "C"}
- error = "IndexError"
ArrayMove(a,i,i2, s,t) (t='error';#[i>=0 && i2>=0,#[i==i2,t=1];s=ArrayRemove(a,i);i=ArrayInsert(a,s,i2);#[i!='error' && s!='error',t=1]];#[t=='error', error='IndexError'];t)
# 1:
Test = {"A", "B", "C"}
r0 = ArrayMove(Test, 0, 2)
# Result: 1
- Test = {"B", "C", "A"}
# 2:
Test = {"A", "B", "C"}
r0 = ArrayMove(Test, 2)
# Result: 1
- Test = {"C", "A", "B"}
# 3:
Test = {"A", "B", "C"}
r0 = ArrayMove(Test)
# Result: 1
- Test = {"A", "B", "C"}
# Error 1:
Test = {"A", "B", "C"}
r0 = ArrayMove(Test, -2, 0)
# Result: 0
- Test = {"A", "B", "C"}
- error = "IndexError"
ArrayExpand(a,a2, n,nt) (n=ArrayLength(a)-1;nt=ArrayLength(a)+ArrayLength(a2);#{++n<nt, a[n]=a2[n-ArrayLength(a2)-1]};a)
# 1:
Test = {"A", "B", "C"}
Test2 = {"D", "E", "F"}
r0 = ArrayExpand(Test, Test2)
# Result: Test = {"A", "B", "C", "D", "E", "F"}
ArrayRange(x,y, a,i) (a={};--x;i=0;#{++x<y, a[i++]=x};a)
# 1:
Test = Range(0,5)
# Result: Test = {"0", "1", "2", "3", "4"}
ArrayReverse(a, n,nt,t) (n=-1;nt=ArrayLength(a);#{++n<nt/2.0, t=a[n];a[n]=a[nt-n-1];a[nt-n-1]=t};a)
# 1:
Test = {"A", "B", "C"}
Reverse(Test)
# Result: Pointer to "Test" array
- Test: {"C", "B", "A"}
ArraySort(a,c) (Sort_Bubble(a,c))
# 1:
Test = {"C", "B", "A"}
Sort(Test)
# Result: Pointer to "Test" array
- Test: {"A", "B", "C"}
ArrayUpdate(a,a2, n,nt,i,t) (n=0;nt=ArrayLength(a2);i=ArrayLength(a);#{n<nt, #[ArrayCount(a, a2[n])==0, ArrayInsert(a, a2[n], i); i++];n++};a)
# 1:
Test = {"A", "B", "C"}
Test2 = {"D", "C", "E"}
ArrayUpdate(Test, Test2)
# Result: Pointer to "Test" array
- Test = {"A", "B", "C", "D", "E"}
- Test2 = {"D", "C", "E"}
ArrayCopy(a, a2,n,nt,t) (a2 = {};n=0;nt=ArrayLength(a);#{n<nt, ArrayInsert(a2,a[n],n);n++};a2)
# 1:
Test = {"A", "B", "C"}
Test2 = ArrayCopy(Test)
# Result: {"A", "B", "C"}
- Test = {"A", "B", "C"}
- Test2 = {"A", "B", "C"}
ArrayCrop(a,n,nt, i) (i=n;#{n<nt, ArrayRemove(a,i);n++};a)
# 1:
Test = {"A", "B", "C"}
r0 = ArrayCrop(Test, 1, 2)
# Result: 1
- Test = {"A"}
# Error 1:
Test = {"A", "B", "C"}
r0 = ArrayCrop(Test, 3, -2)
# Result: "error"
- Test = {"A", "B", "C"}
- error = "IndexError"
ArrayToString(a,sep, n,nt,t) (n=-1;t="";nt=ArrayLength(a);#{++n<nt, t=t+a[n]+sep};t=t[0,-l(sep)-1];t)
StringToArray(s,sep, n,i) (a={};n=-1;#{i = StrLoc(s,sep); i!=-1, a[++n]=s[0,i-l(sep)]; s=s[i+l(sep),-1]};a[++n]=s;a)
Sort_Bubble(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++]}})
StrLoc(s,e, p,i) (p=-1;i=0;#{(i<l(s))&&(p<0),#[s[i,i+l(e)-1]==e,p=i];i++};p)
ArrayLength(a, i) (i=0;f=0;#{#[a[i] == 0,++f, f=0];f<2, ++i};i-1)
ArrayInsert(a,s,i, n,nf,nt,s2,t) (t='error'; #[s!='',n=-1;nf=0;s2=0;nt=ArrayLength(a)+1;#{n++<nt,#[n>=i, #[n==i, t=1];#[nf%2==0,#[n!=nt,s2=a[n]];a[n]=s];#[nf%2==1,#[n!=nt,s=a[n]];a[n]=s2];++nf]}];#[t=='error', error='ValueError'];t)
ArrayCount(a,s, n,nt,t) (t='error';#[s!="",n=-1;t=0;nt=ArrayLength(a);#{++n<nt, #[a[n]==s, ++t]}, t=ArrayLength(a)];t)
ArrayRemove(a,i, n,nf,nt,s,s2,t) (t='error';#[i>=0,n=-1;nf=0;s=s2=0;nt=ArrayLength(a);#{nt-->n,#[nt>=i, #[nt==i, t=a[i]];#[nf%2==0,#[nt!=n,s2=a[nt]];a[nt]=s];#[nf%2==1,#[nt!=n,s=a[nt]];a[nt]=s2];++nf]}];#[t=='error', error='IndexError'];t)
ArrayIndex(a,s,it, f,i,n,nt,t) (t='error';#[s!='',n=-1;nt=ArrayLength(a); i=0;f=0; #[it<0, n=nt;nt=-1;it*=-1;f=1];#[it==0, it=1];#{#[f==1, --n>nt,++n<nt] && i<it, #[a[n]==s, ++i]};#[i>=it, #[f==1, t=++n, t=--n]]];#[t=='error' && s=='',error='ValueError', #[t=='error', error='IndexError']];t)
ArrayExpand(a,a2, n,nt,t) (n=ArrayLength(a)-1;nt=ArrayLength(a)+ArrayLength(a2);#{++n<nt, a[n]=a2[n-ArrayLength(a2)-1]};a)
ArrayRange(x,y, a,i) (a={};--x;i=0;#{++x<y, a[i++]=x};a)
ArrayReverse(a, n,nt,t) (n=-1;nt=ArrayLength(a);#{++n<nt/2.0, t=a[n];a[n]=a[nt-n-1];a[nt-n-1]=t};a)
ArrayAppend(a,s) (t=ArrayInsert(a,s,ArrayLength(a));t)
ArrayPop(a) (t=ArrayRemove(a,ArrayLength(a)-1);t)
ArrayRemoveRepeated(a,s, n,nt,t,f) (#[s==0, f=1];n=-1;nt=ArrayLength(a);t='error';#{#[f==1, s=a[n+1];++n<nt && ArrayCount(a,s)>1,ArrayCount(a,s)>1], ArrayRemove(a, ArrayIndex(a,s,2)); t=1};#[t=='error', error='ValueError'];t)
ArrayRemoveItem(a,s,it, i,n,nt,t) (t='error';#[s!="" && i>=0, n=-1;nt=ArrayCount(a,s);i=0;#{++n<=nt, #[a[s]==s, #[i>=it; t=ArrayRemove(a,n)}];#[t!='error',t=1];t)
ArraySwap(a,i,i2, s,s2,t) (t='error';#[i==i2,t=1];#[i2>i,s=i;i=i2;i2=s];s=ArrayRemove(a,i);s2=ArrayRemove(a,i2);i2=ArrayInsert(a,s,i2);i=ArrayInsert(a,s2,i);#[i!='error' && i2!='error' && s!='error' && s2!='error',t=1];#[t=='error', error='ValueError'];t)
ArrayMove(a,i,i2, s,t) (t='error';#[i>=0 && i2>=0,#[i==i2,t=1];s=ArrayRemove(a,i);i=ArrayInsert(a,s,i2);#[i!='error' && s!='error',t=1]];#[t=='error', error='IndexError'];t)
ArraySort(a,c) (Sort_Bubble(a,c))
ArrayUpdate(a,a2, n,nt,i,t) (n=0;nt=ArrayLength(a2);i=ArrayLength(a);#{n<nt, #[ArrayCount(a, a2[n])==0, ArrayInsert(a, a2[n], i); i++];n++};a)
ArrayCopy(a, a2,n,nt,t) (a2 = {};n=0;nt=ArrayLength(a);#{n<nt, ArrayInsert(a2,a[n],n);n++};a2)
ArrayCrop(a,n,nt, i) (i=n;#{n<nt, ArrayRemove(a,i);n++};a)
ArrayItemGet(a,i,it ,a2,itmp,nt) (a2={};itmp=nt=-1;#[it==0,#[l(a)+i>=0&&i<l(a),#[i>=0,itmp=a[i],itmp=a[l(a)+i]],'IndexError'],#[it==1,#{++nt<2-1,#[i[nt]<0,i[nt]=l(a)+i[nt]]};nt=-1;itmp=i[0]-1;#{++nt;++itmp<=i[1]-1,#[itmp<l(a),a2[nt]=a[itmp];a2]};a2,#[it==2,#{++nt;nt<=l(i)-1,#[l(a)+i[nt]>=0&&i[nt]<l(a),++itmp;#[i[nt]>=0,a2[itmp]=a[i[nt]],a2[itmp]=a[l(a)+i[nt]]];a2]};a2,'ValueError']]])
ArrayToString(a,sep, n,nt,t) (n=-1;t="";nt=ArrayLength(a);#{++n<nt, t=t+a[n]+sep};t=t[0,-l(sep)-1];t)
StringToArray(s,sep, n,i) (a={};n=-1;#{i = StrLoc(s,sep); i!=-1, a[++n]=s[0,i-l(sep)]; s=s[i+l(sep),-1]};a[++n]=s;a)
;I need to rename function names to be only for items or for arrays by complete.
;Math Header System:
;To define a number:
;- ${MathNumDef} "numbername"
;To initialize a number:
;- ${MathNumInit} "numbername" "data" "subtype"
;To use a number:
;StrCpy $0 $n_numbername
;RGB <-> HSL
;References
http://130.113.54.154/~monger/hsl-rgb.html
http://www.easyrgb.com/math.php?MATH=M18#text18
http://en.wikipedia.org/wiki/HSV_color_space
http://www.cs.bham.ac.uk/~mer/colour/hsv.html
RGBToHSL(R,G,B, RGBMAX,HLSMAX, cMax,cMin,Rdelta,Gdelta,Bdelta) (#[RGBMAX==0,RGBMAX=255.0];#[HLSMAX==0,HLSMAX=240.0];cMin=#[R<G&&R<B,R,#[G<B,G,B]];cMax=#[R>G&&R>B,R,#[G>B,G,B]];L=(((cMax+cMin)*HLSMAX)+RGBMAX)/(2*RGBMAX);#[cMax==cMin,H=(HLSMAX*2.0/3);s=0.0,#[L<=(HLSMAX/2),s=(((cMax-cMin)*HLSMAX)+((cMax+cMin)/2))/(cMax+cMin),s=(((cMax-cMin)*HLSMAX)+((2*RGBMAX-cMax-cMin)/2))/(2*RGBMAX-cMax-cMin)];Rdelta=(((cMax-R)*(HLSMAX/6))+((cMax-cMin)/2))/(cMax-cMin);Gdelta=(((cMax-G)*(HLSMAX/6))+((cMax-cMin)/2))/(cMax-cMin);Bdelta=(((cMax-B)*(HLSMAX/6))+((cMax-cMin)/2))/(cMax-cMin);#[R==cMax,H=Bdelta-Gdelta,#[G==cMax,H=(HLSMAX/3)+Rdelta-Bdelta,#[B==cMax,H=((2*HLSMAX)/3)+Gdelta-Rdelta]]];#[H<0,H+=HLSMAX];#[H>HLSMAX,H-=HLSMAX]];H=#[fra(H)<0.5,H=flr(H),H=cel(H)];s=flr(s);L=flr(L))
RGBToHSL(212,52,97)
H - Round normal (when < 0.5, to below, => 0.5, to above)
Rest, round downward.
Reason:
H range of values is 0-239, w/ 240 numbers in total. Numbers never reach above 240, so normal rounding can be applied.
S range of values is 0-240, w/ 241 numbers in total. Numbers CAN reach up to 240.5. If it was to be rounded normally, it would go to 241, which wouldn't be good, because no number reached 241.
L is the same thing as S.
RGB->HLS
HueToRGB(n1,n2,H, HLSMAX) (#[HLSMAX==0,HLSMAX=240.0,HLSMAX+=0.0];#[H<0,H+=HLSMAX];#[H>HLSMAX,H-=HLSMAX];#[H<(HLSMAX/6),n1+(((n2-n1)*H+(HLSMAX/12))/(HLSMAX/6)),#[H<(HLSMAX/2),n2,#[H<((HLSMAX*2)/3),n1+(((n2-n1)*(((HLSMAX*2)/3)-H)+(HLSMAX/12))/(HLSMAX/6)),n1]]])
HLSToRGB(H,L,s, HLSMAX,RGBMAX) (#[HLSMAX==0,HLSMAX=240.0];#[RGBMAX==0,RGBMAX=255.0];#[s==0,R=G=B=(L*RGBMAX)/HLSMAX;#[H!=(HLSMAX*2/3),error="ValueError"],#[L<=(HLSMAX/2),Magic2=(L*(HLSMAX+s)+(HLSMAX/2))/HLSMAX,Magic2=L+s-((L*s)+(HLSMAX/2))/HLSMAX];Magic1=2*L-Magic2;R = (HueToRGB(Magic1,Magic2,H+(HLSMAX/3))*RGBMAX+(HLSMAX/2))/HLSMAX;G = (HueToRGB(Magic1,Magic2,H)*RGBMAX + (HLSMAX/2))/HLSMAX;B = (HueToRGB(Magic1,Magic2,H-(HLSMAX/3))*RGBMAX+(HLSMAX/2))/HLSMAX])
Couldn't finish HLSToRGB to accuratelly output consistant results. There is always results in the range 1+/-.
| |||||||||||||||||||||||||
|
| |||||
|