summaryrefslogtreecommitdiff
path: root/app/schulis-mathematiksystem/1.0/src/mat.vector
blob: 03439bcc7fb950790bedbaf2933aef081eaad549 (plain)
1
2
PACKETvectorDEFINES VECTOR,:=,vector,SUB,LENGTH,length,nilvector,replace,=,<>,+,-,*,/:TYPE VECTOR=STRUCT(INTlng,TEXTelem),INITVECTOR=STRUCT(INTlng,REALvalue);INT VARi;TEXT VARt:="12345678";VECTOR VARv:=nilvector;OP:=(VECTOR VARl,VECTOR CONSTr):l.lng:=r.lng;l.elem:=r.elemEND OP:=;OP:=(VECTOR VARl,INITVECTOR CONSTr):l.lng:=r.lng;replace(t,1,r.value);l.elem:=r.lng*tEND OP:=;INITVECTOR PROCnilvector:vector(1,0.0)END PROCnilvector;INITVECTOR PROCvector(INT CONSTlng,REAL CONSTvalue):IFlng<=0THENerrorstop("PROC vector : lng <= 0")FI;INITVECTOR:(lng,value)END PROCvector;INITVECTOR PROCvector(INT CONSTlng):vector(lng,0.0)END PROCvector;REAL OP SUB(VECTOR CONSTv,INT CONSTi):test("REAL OP SUB : ",v,i);v.elemRSUBiEND OP SUB;INT OP LENGTH(VECTOR CONSTv):v.lngEND OP LENGTH;INT PROClength(VECTOR CONSTv):v.lngEND PROClength;PROCreplace(VECTOR VARv,INT CONSTi,REAL CONSTr):test("PROC replace : ",v,i);replace(v.elem,i,r)END PROCreplace;BOOL OP=(VECTOR CONSTl,r):l.elem=r.elemEND OP=;BOOL OP<>(VECTOR CONSTl,r):l.elem<>r.elemEND OP<>;VECTOR OP+(VECTOR CONSTv):vEND OP+;VECTOR OP+(VECTOR CONSTl,r):test("VECTOR OP + : ",l,r);v:=l;FORiFROM1UPTOv.lngREPreplace(v.elem,i,(l.elemRSUBi)+(r.elemRSUBi))PER;vEND OP+;VECTOR OP-(VECTOR CONSTa):v:=a;FORiFROM1UPTOv.lngREPreplace(v.elem,i,-(a.elemRSUBi))PER;vEND OP-;VECTOR OP-(VECTOR CONSTl,r):test("VECTOR OP - : ",l,r);v:=l;FORiFROM1UPTOv.lngREPreplace(v.elem,i,(l.elemRSUBi)-(r.elemRSUBi))PER;vEND OP-;REAL OP*(VECTOR CONSTl,r):test("REAL OP * : ",l,r);REAL VARx:=0.0;FORiFROM1UPTOl.lngREPxINCR((l.elemRSUBi)*(r.elemRSUBi))PER;xEND OP*;VECTOR OP*(VECTOR CONSTv,REAL CONSTr):r*vEND OP*;VECTOR OP*(REAL CONSTr,VECTOR CONSTa):v:=a;FORiFROM1UPTOv.lngREPreplace(v.elem,i,r*(a.elemRSUBi))PER;vEND OP*;VECTOR OP/(VECTOR CONSTa,REAL CONSTr):v:=a;FORiFROM1UPTOv.lngREPreplace(v.elem,i,(a.elemRSUBi)/r)PER;vEND OP/;TEXT VARerror:="";PROCtest(TEXT CONSTproc,VECTOR CONSTv,INT CONSTi):IFi>v.lngTHENerror:=proc;errorCAT"subscript overflow (LENGTH v=";errorCATtext(v.lng);errorCAT", i=";errorCATtext(i);errorCAT")";errorstop(error)ELIFi<1THENerror:=proc;errorCAT"subscript underflow (i = ";errorCATtext(i);errorCAT")";errorstop(error)FI END PROCtest;PROCtest(TEXT CONSTproc,VECTOR CONSTa,b):IFa.lng<>b.lngTHENerror:=proc;errorCAT"LENGTH a (";IFa.lng<=0THENerrorCAT"undefined"ELSEerrorCATtext(a.lng)FI;errorCAT") <> LENGTH b (";errorCATtext(b.lng);errorCAT")";errorstop(error)FI END PROCtest;END PACKETvector;