From: Jorge G. <cl...@us...> - 2006-09-22 15:06:38
|
Update of /cvsroot/easycalc/easycalc/mlib In directory sc8-pr-cvs5.sourceforge.net:/tmp/cvs-serv5686/mlib Modified Files: cmatrix.c funcs.c matrix.c Log Message: matrix[i] returns row i of matrix in a list Index: cmatrix.c =================================================================== RCS file: /cvsroot/easycalc/easycalc/mlib/cmatrix.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** cmatrix.c 12 Sep 2006 19:40:56 -0000 1.24 --- cmatrix.c 22 Sep 2006 15:06:32 -0000 1.25 *************** *** 1213,1214 **** --- 1213,1276 ---- return err; } + + /*********************************************************************** + * + * FUNCTION: cmatrix_item + * + * DESCRIPTION: Function for the M[1:2] type of operation + * + * PARAMETERS: matrix, row [, column] + * + * RETURN: complex number or list + * + ***********************************************************************/ + CError + cmatrix_item(Functype *func, CodeStack *stack) + { + UInt32 row,col; + CError err; + Complex result; + CMatrix *m; + + if (func->paramcount == 3){ + err = stack_get_val(stack, &col, integer); + if (err) + return err; + } + else{ + if (func->paramcount != 2) + return c_badargcount; + col=1; + } + + err = stack_get_val(stack, &row, integer); + if (err) + return err; + + err = stack_get_val(stack, &m, cmatrix); + if (err) + return err; + + if (col > m->cols || row > m->rows || col == 0 || row == 0) + return c_baddim; + + if (func->paramcount == 2){ + List *lresult; + int i; + + lresult = list_new(m->cols); + for(i=0;i<m->cols;i++){ + lresult->item[i] = MATRIX(m,row-1,i); + } + stack_add_val(stack,&lresult,list); + list_delete(lresult); + } + else{ + result = MATRIX(m,row-1,col-1); + stack_add_val(stack, &result, complex); + } + + cmatrix_delete(m); + return c_noerror; + + } \ No newline at end of file Index: matrix.c =================================================================== RCS file: /cvsroot/easycalc/easycalc/mlib/matrix.c,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** matrix.c 12 Sep 2006 19:40:56 -0000 1.28 --- matrix.c 22 Sep 2006 15:06:33 -0000 1.29 *************** *** 893,899 **** * DESCRIPTION: Function for the M[1:2] type of operation * ! * PARAMETERS: matrix, row, column * ! * RETURN: real number * ***********************************************************************/ --- 893,899 ---- * DESCRIPTION: Function for the M[1:2] type of operation * ! * PARAMETERS: matrix, row [, column] * ! * RETURN: real number or list * ***********************************************************************/ *************** *** 904,951 **** CError err; double result; ! Complex cresult; ! rpntype type; ! if (func->paramcount != 3) ! return c_badargcount; - err = stack_get_val(stack, &col, integer); - if (err) - return err; err = stack_get_val(stack, &row, integer); if (err) return err; ! err = stack_item_type(stack,&type,0); ! if (err) return err; ! if (type == matrix) { ! Matrix *m; ! err = stack_get_val(stack, &m, matrix); ! if (err) ! return err; ! if (col > m->cols || row > m->rows || ! col == 0 || row == 0) ! return c_baddim; ! result = MATRIX(m,row-1,col-1); ! err = stack_add_val(stack, &result, real); ! matrix_delete(m); ! } else if (type == cmatrix) { ! CMatrix *m; ! err = stack_get_val(stack, &m, cmatrix); ! if (err) ! return err; ! if (col > m->cols || row > m->rows || ! col == 0 || row == 0) ! return c_baddim; ! ! cresult = MATRIX(m,row-1,col-1); ! err = stack_add_val(stack, &cresult, complex); ! cmatrix_delete(m); ! } else ! err = c_badarg; ! return err; } --- 904,951 ---- CError err; double result; ! Matrix *m; ! if (func->paramcount == 3){ ! err = stack_get_val(stack, &col, integer); ! if (err) ! return err; ! } ! else{ ! if (func->paramcount != 2) ! return c_badargcount; ! col=1; ! } err = stack_get_val(stack, &row, integer); if (err) return err; ! err = stack_get_val(stack, &m, matrix); ! if (err) return err; ! if (col > m->cols || row > m->rows || col == 0 || row == 0) ! return c_baddim; ! ! if (func->paramcount == 2){ ! List *lresult; ! int i; ! ! lresult = list_new(m->cols); ! for(i=0;i<m->cols;i++){ ! lresult->item[i].real = MATRIX(m,row-1,i); ! lresult->item[i].imag = 0.0; ! } ! stack_add_val(stack,&lresult,list); ! list_delete(lresult); ! } ! else{ result = MATRIX(m,row-1,col-1); ! stack_add_val(stack, &result, real); ! } ! ! matrix_delete(m); ! return c_noerror; ! } Index: funcs.c =================================================================== RCS file: /cvsroot/easycalc/easycalc/mlib/funcs.c,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** funcs.c 12 Sep 2006 19:40:56 -0000 1.49 --- funcs.c 22 Sep 2006 15:06:33 -0000 1.50 *************** *** 45,48 **** --- 45,49 ---- #include "slist.h" #include "matrix.h" + #include "cmatrix.h" /* If we are just drawing the graph, set this variable. */ *************** *** 1028,1040 **** func_item(Functype *func, CodeStack *stack) { ! rpntype type1; ! UInt32 arg1=0,arg2=0; ! Trpn item,ritem; CError err; if (func->paramcount == 2) ! err = stack_item_type_nr(stack,&type1,1); else if (func->paramcount == 3) ! err = stack_item_type_nr(stack,&type1,2); else err = c_badargcount; --- 1029,1039 ---- func_item(Functype *func, CodeStack *stack) { ! rpntype type; CError err; if (func->paramcount == 2) ! err = stack_item_type(stack,&type,1); else if (func->paramcount == 3) ! err = stack_item_type(stack,&type,2); else err = c_badargcount; *************** *** 1042,1067 **** return err; ! if (type1 == variable) { ! err = stack_get_val(stack,&arg2,integer); ! if (err) ! return err; ! if (func->paramcount == 3) { ! err = stack_get_val(stack,&arg1,integer); ! if (err) ! return err; ! } ! item = stack_pop(stack); ! ritem.allocsize = 0; ! ritem.type = litem; ! StrCopy(ritem.u.litemval.name,item.u.varname); ! ritem.u.litemval.row = arg1; ! ritem.u.litemval.col = arg2; ! stack_push(stack,ritem); ! rpn_delete(item); ! } else if (func->paramcount == 2) return list_item(func,stack); ! else return matrix_item(func,stack); ! return c_noerror; } #else /* Not specfun enabled */ --- 1041,1055 ---- return err; ! switch (type){ ! case list: return list_item(func,stack); ! case matrix: return matrix_item(func,stack); ! case cmatrix: ! return cmatrix_item(func,stack); ! default: ! return c_badarg; ! } ! } #else /* Not specfun enabled */ |