From 55ab04285dec8af49e075479773e50b6bec17fcc Mon Sep 17 00:00:00 2001 From: MPo Date: Sun, 6 Nov 2016 16:28:23 +0100 Subject: [PATCH] lib64: added PMUL (polynomial multiplication) --- newrpl/lib-64-arithmetic.c | 128 +++++++++++++++++++++++++++++++++---- 1 file changed, 117 insertions(+), 11 deletions(-) diff --git a/newrpl/lib-64-arithmetic.c b/newrpl/lib-64-arithmetic.c index 117f88a..5e23f6c 100644 --- a/newrpl/lib-64-arithmetic.c +++ b/newrpl/lib-64-arithmetic.c @@ -2252,17 +2252,17 @@ void LIB_HANDLER() // DO IT ALL WITH REALS WORDPTR *savestk=DSTop; // Drop arguments in case of error - BINT can_reduce = 0; + BINT leading_zeroes_arg = 0; for(f=0;f nelem2 ? nelem1 : nelem2; // degree = max(degree1, degree2) @@ -2375,13 +2375,13 @@ void LIB_HANDLER() for (f = 0; f < nelem3; ++f) { BINT i1 = cols1-nelem3+f; BINT i2 = cols2-nelem3+f; - if (i1 < can_reduce_a1) { + if (i1 < leading_zeroes_arg1) { rplBINTToRReg(1,0); } else { WORDPTR entry=rplMatrixFastGet(arg1,1,i1+1); rplNumberToRReg(1, entry); } - if (i2 < can_reduce_a2) { + if (i2 < leading_zeroes_arg2) { rplBINTToRReg(2,0); } else { WORDPTR entry=rplMatrixFastGet(arg2,1,i2+1); @@ -2426,7 +2426,113 @@ void LIB_HANDLER() return; } + case PMUL: + { + if(rplDepthData()<2) { + rplError(ERR_BADARGCOUNT); + return; + } + WORDPTR arg1=rplPeekData(2); + WORDPTR arg2=rplPeekData(1); + + // POLYNOMIAL DIVISION + if(ISMATRIX(*arg1) && ISMATRIX(*arg2)) { + BINT rows1=MATROWS(arg1[1]),cols1=MATCOLS(arg1[1]); + BINT rows2=MATROWS(arg2[1]),cols2=MATCOLS(arg2[1]); + // Check for vector only + if(rows1 || rows2) { + rplError(ERR_VECTOREXPECTED); + return; + } + + // only numbers allowed + BINT f; + for(f=0;fsavestk) DSTop=savestk; + return; + } + rplOverwriteData(nout-iout, newnumber); + } + } + } + } + WORDPTR poly=rplMatrixCompose(0,nout); + if(!poly || Exceptions) { + if(DSTop>savestk) DSTop=savestk; + return; + } + rplDropData(nout+1); + rplOverwriteData(1,poly); + + } + else { + rplError(ERR_VECTOROFNUMBERSEXPECTED); + } + return; + }