Update of /cvsroot/easycalc/PPCport/core/mlib In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv32113 Modified Files: display.cpp display.h fp.cpp funcs.cpp funcs.h integ.cpp konvert.cpp mathem.cpp txtask.cpp Log Message: Release 1.25e Index: display.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/display.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** display.h 17 Oct 2009 13:48:34 -0000 1.4 --- display.h 15 Dec 2009 21:37:44 -0000 1.5 *************** *** 54,58 **** TCHAR * display_complex(Complex number) MLIB; TCHAR * display_integer(UInt32 number,Tbase mode) MLIB; ! TCHAR * display_default(Trpn rpn,Boolean complete) MLIB; TCHAR * display_list(List *list) MLIB; --- 54,58 ---- TCHAR * display_complex(Complex number) MLIB; TCHAR * display_integer(UInt32 number,Tbase mode) MLIB; ! TCHAR * display_default(Trpn rpn,Boolean complete,rpntype *resultType) MLIB; TCHAR * display_list(List *list) MLIB; Index: funcs.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/funcs.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** funcs.cpp 25 Oct 2009 17:52:34 -0000 1.6 --- funcs.cpp 15 Dec 2009 21:37:44 -0000 1.7 *************** *** 897,928 **** tmp = res; if (func->num==FUNC_RADIAN) { ! fp_print_double(res,arg/M_PIl); StrCat(res,_T("pi")); } else if (func->num==FUNC_DEGREE || func->num == FUNC_DEGREE2) { ! if (arg<0) { *tmp++=_T('-'); ! arg=-arg; } /* The numbers must be added 1E-12 to avoid cases like 1+5/60 -> 1o04' */ ! fp_print_double(tmp,trunc(arg+1E-12)); tmp+=StrLen(tmp); *tmp++=_T('°'); ! if (arg-trunc(arg)<1E-15) StrCopy(tmp,_T("0\'")); else { if (func->num == FUNC_DEGREE) { ! fp_print_double(tmp,trunc(60*(arg-trunc(arg+1E-12))+1E-12)); tmp+=StrLen(tmp); *tmp++=_T('\''); ! fp_print_double(tmp,60*(arg*60-trunc(arg*60+1E-12))); } else { /* FUNC_DEGREE2 */ ! fp_print_double(tmp,60*(arg-trunc(arg+1E-12))+1E-12); StrCat(tmp,_T("'")); } } } err = stack_add_val(stack,res,string); --- 897,969 ---- tmp = res; if (func->num==FUNC_RADIAN) { ! // Mapi: take calculator mode in account for conversion ! // Allows to convert from one unit to another and display result. ! // Also reduce to the range ]-2pi,2pi[. ! double conv; ! if (calcPrefs.trigo_mode == degree) { ! conv = fmod(arg/180.0, 2.0); ! } else if (calcPrefs.trigo_mode == radian) { ! conv = fmod(arg/M_PIl, 2.0); ! } else { // Grads ! conv = fmod(arg/200.0, 2.0); ! } ! fp_print_double(res, conv); StrCat(res,_T("pi")); } else if (func->num==FUNC_DEGREE || func->num == FUNC_DEGREE2) { ! // Mapi: take calculator mode in account for conversion ! // Allows to convert from one unit to another and display result. ! // Also reduce to the range ]-360,360[. ! double conv; ! if (calcPrefs.trigo_mode == degree) { ! conv = fmod(arg, 360.0); ! } else if (calcPrefs.trigo_mode == radian) { ! conv = fmod(arg/M_PIl*180.0, 360.0); ! } else { // Grads ! conv = fmod(arg/10.0*9.0, 360.0); ! } ! if (conv<0) { *tmp++=_T('-'); ! conv=-conv; } /* The numbers must be added 1E-12 to avoid cases like 1+5/60 -> 1o04' */ ! fp_print_double(tmp,trunc(conv+1E-12)); tmp+=StrLen(tmp); *tmp++=_T('°'); ! if (conv-trunc(conv)<1E-15) StrCopy(tmp,_T("0\'")); else { if (func->num == FUNC_DEGREE) { ! fp_print_double(tmp,trunc(60*(conv-trunc(conv+1E-12))+1E-12)); tmp+=StrLen(tmp); *tmp++=_T('\''); ! fp_print_double(tmp,60*(conv*60-trunc(conv*60+1E-12))); } else { /* FUNC_DEGREE2 */ ! fp_print_double(tmp,60*(conv-trunc(conv+1E-12))+1E-12); StrCat(tmp,_T("'")); } } } + else if (func->num==FUNC_GRAD) { + // Mapi: new function. + // Take calculator mode in account for conversion + // Allows to convert from one unit to another and display result. + // Also reduce to the range ]-400,400[. + double conv; + if (calcPrefs.trigo_mode == degree) { + conv = fmod(arg/9.0*10.0, 400.0); + } else if (calcPrefs.trigo_mode == radian) { + conv = fmod(arg/M_PIl*200.0, 400.0); + } else { // Grads + conv = fmod(arg, 400.0); + } + if (conv<0) { + *tmp++=_T('-'); + conv=-conv; + } + fp_print_double(res, conv); + } err = stack_add_val(stack,res,string); Index: funcs.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/funcs.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** funcs.h 25 Oct 2009 17:52:34 -0000 1.5 --- funcs.h 15 Dec 2009 21:37:44 -0000 1.6 *************** *** 75,78 **** --- 75,79 ---- #define FUNC_TOCIS 4 #define FUNC_DEGREE2 5 + #define FUNC_GRAD 6 #define RAND_NUM ((double) SysRandom(0) / (double)sysRandomMax) Index: mathem.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/mathem.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** mathem.cpp 17 Oct 2009 13:48:34 -0000 1.1 --- mathem.cpp 15 Dec 2009 21:37:44 -0000 1.2 *************** *** 972,991 **** } ! #define FIN_FV_BEGIN(I,N,PV,PMT,PYR) (-(PV*pow(1+(I/PYR/100),N)+PMT*(1+(I/PYR/100))*(pow(1+(I/PYR/100),N)-1)/(I/PYR/100))) ! #define FIN_FV_END(I,N,PV,PMT,PYR) (-(PV*pow(1+(I/PYR/100),N)+PMT*(pow(1+(I/PYR/100),N)-1)/(I/PYR/100))) ! #define FIN_FV_ZERO(I,N,PV,PMT,PYR) (-(PV+PMT*N)) ! ! #define FIN_PV_BEGIN(I,N,PMT,FV,PYR) ((-FV-PMT*(1+(I/PYR/100))*(pow(1+(I/PYR/100),N)-1)/(I/PYR/100))/pow(1+(I/PYR/100),N)) ! #define FIN_PV_END(I,N,PMT,FV,PYR) ((-FV-PMT*(pow(1+(I/PYR/100),N)-1)/(I/PYR/100))/pow(1+(I/PYR/100),N)) ! #define FIN_PV_ZERO(I,N,PMT,FV,PYR) (-PMT*N-FV) ! #define FIN_PMT_BEGIN(I,N,PV,FV,PYR) ((-FV-PV*pow(1+(I/PYR/100),N))*((I/PYR/100)/(pow(1+(I/PYR/100),N)-1)/(1+(I/PYR/100)))) ! #define FIN_PMT_END(I,N,PV,FV,PYR) ((-FV-PV*pow(1+(I/PYR/100),N))*(I/PYR/100)/(pow(1+(I/PYR/100),N)-1)) ! #define FIN_PMT_ZERO(I,N,PV,FV,PYR) (-(FV+PV)/N) ! #define FIN_N_BEGIN(I,PV,PMT,FV,PYR) (log10((-FV*(I/PYR/100)+PMT*(1+(I/PYR/100)))/(PV*(I/PYR/100)+PMT*(1+(I/PYR/100))))/log10(1+(I/PYR/100))) ! #define FIN_N_END(I,PV,PMT,FV,PYR) (log10((-FV*(I/PYR/100)+PMT)/(PV*(I/PYR/100)+PMT))/log10(1+(I/PYR/100))) ! #define FIN_N_ZERO(I,PV,PMT,FV,PYR) (-(FV+PV)/PMT) CError --- 972,1010 ---- } ! // Mapi: rewrite for better calculation precision ! //#define FIN_FV_BEGIN(I,N,PV,PMT,PYR) (-(PV*pow(1+(I/PYR/100),N)+PMT*(1+(I/PYR/100))*(pow(1+(I/PYR/100),N)-1)/(I/PYR/100))) ! //#define FIN_FV_END(I,N,PV,PMT,PYR) (-(PV*pow(1+(I/PYR/100),N)+PMT*(pow(1+(I/PYR/100),N)-1)/(I/PYR/100))) ! //#define FIN_FV_ZERO(I,N,PV,PMT,PYR) (-(PV+PMT*N)) ! // Mapi: bug correction (on global sign of formula) ! #define FIN_FV_BEGIN(I,N,PV,PMT,PYR) (-((-(PV)-(PMT)*((PYR)*100.0/(I)+1.0))*pow(1.0+(I)/100.0/(PYR),(N))+(PMT)*((PYR)*100.0/(I)+1.0))) ! #define FIN_FV_END(I,N,PV,PMT,PYR) (-((-(PV)-(PMT)*(PYR)*100.0/(I))*pow(1.0+(I)/100.0/(PYR),(N))+(PMT)*(PYR)*100.0/(I))) ! #define FIN_FV_ZERO(N,PV,PMT) (-(-(PV)-(PMT)*(N))) ! //#define FIN_PV_BEGIN(I,N,PMT,FV,PYR) ((-FV-PMT*(1+(I/PYR/100))*(pow(1+(I/PYR/100),N)-1)/(I/PYR/100))/pow(1+(I/PYR/100),N)) ! //#define FIN_PV_END(I,N,PMT,FV,PYR) ((-FV-PMT*(pow(1+(I/PYR/100),N)-1)/(I/PYR/100))/pow(1+(I/PYR/100),N)) ! //#define FIN_PV_ZERO(I,N,PMT,FV,PYR) (-PMT*N-FV) ! // Mapi: bug correction (on global sign of formula) ! #define FIN_PV_BEGIN(I,N,PMT,FV,PYR) (-((-(FV)-(PMT)*((PYR)*100.0/(I)+1.0))/pow(1.0+(I)/100.0/(PYR),(N))+(PMT)*((PYR)*100.0/(I)+1.0))) ! #define FIN_PV_END(I,N,PMT,FV,PYR) (-((-(FV)-(PMT)*(PYR)*100.0/(I))/pow(1.0+(I)/100.0/(PYR),(N))+(PMT)*(PYR)*100.0/(I))) ! // Mapi: bug correction (on sign of FV) ! #define FIN_PV_ZERO(N,PMT,FV) (-(-(FV)+(PMT)*(N))) ! //#define FIN_PMT_BEGIN(I,N,PV,FV,PYR) ((-FV-PV*pow(1+(I/PYR/100),N))*((I/PYR/100)/(pow(1+(I/PYR/100),N)-1)/(1+(I/PYR/100)))) ! //#define FIN_PMT_END(I,N,PV,FV,PYR) ((-FV-PV*pow(1+(I/PYR/100),N))*(I/PYR/100)/(pow(1+(I/PYR/100),N)-1)) ! //#define FIN_PMT_ZERO(I,N,PV,FV,PYR) (-(FV+PV)/N) ! // Mapi: bug correction (on sign of FV) ! #define FIN_PMT_BEGIN(I,N,PV,FV,PYR) (((FV)-(PV)*pow(1.0+(I)/100.0/(PYR),(N)))/(pow(1.0+(I)/100.0/(PYR),(N))-1.0)*(I)/(100.0*(PYR)+(I))) ! #define FIN_PMT_END(I,N,PV,FV,PYR) (((FV)-(PV)*pow(1.0+(I)/100.0/(PYR),(N)))/(pow(1.0+(I)/100.0/(PYR),(N))-1.0)*(I)/100.0/(PYR)) ! #define FIN_PMT_ZERO(N,PV,FV) (-((PV)-(FV))/(N)) + // Mapi: bug correction (on sign of PMT) + //#define FIN_N_BEGIN(I,PV,PMT,FV,PYR) (log10((-FV*(I/PYR/100)+PMT*(1+(I/PYR/100)))/(PV*(I/PYR/100)+PMT*(1+(I/PYR/100))))/log10(1+(I/PYR/100))) + //#define FIN_N_END(I,PV,PMT,FV,PYR) (log10((-FV*(I/PYR/100)+PMT)/(PV*(I/PYR/100)+PMT))/log10(1+(I/PYR/100))) + //#define FIN_N_ZERO(I,PV,PMT,FV,PYR) (-(FV+PV)/PMT) + // Mapi: bug correction (on sign of PV) + #define FIN_N_BEGIN(I,PV,PMT,FV,PYR) (log((-(FV)-(PMT)*((PYR)*100.0/(I)+1.0))/(-(PV)-(PMT)*((PYR)*100.0/(I)+1.0)))/log(1.0+(I)/100.0/(PYR))) + #define FIN_N_END(I,PV,PMT,FV,PYR) (log((-(FV)-(PMT)*(PYR)*100.0/(I))/(-(PV)-(PMT)*(PYR)*100.0/(I)))/log(1.0+(I)/100.0/(PYR))) + // Mapi: bug correction (on sign of FV) + #define FIN_N_ZERO(PV,PMT,FV) (-((PV)-(FV))/(PMT)) CError *************** *** 1012,1016 **** case MATH_FINPMT: if (arg[0] == 0.0) ! result = FIN_PMT_ZERO(arg[0],arg[1],arg[2],arg[3],arg[4]); else if (begin) result = FIN_PMT_BEGIN(arg[0],arg[1],arg[2],arg[3],arg[4]); --- 1031,1035 ---- case MATH_FINPMT: if (arg[0] == 0.0) ! result = FIN_PMT_ZERO(arg[1],arg[2],arg[3]); else if (begin) result = FIN_PMT_BEGIN(arg[0],arg[1],arg[2],arg[3],arg[4]); *************** *** 1020,1024 **** case MATH_FINPV: if (arg[0] == 0.0) ! result = FIN_PV_ZERO(arg[0],arg[1],arg[2],arg[3],arg[4]); else if (begin) result = FIN_PV_BEGIN(arg[0],arg[1],arg[2],arg[3],arg[4]); --- 1039,1043 ---- case MATH_FINPV: if (arg[0] == 0.0) ! result = FIN_PV_ZERO(arg[1],arg[2],arg[3]); else if (begin) result = FIN_PV_BEGIN(arg[0],arg[1],arg[2],arg[3],arg[4]); *************** *** 1028,1032 **** case MATH_FINN: if (arg[0] == 0.0) ! result = FIN_N_ZERO(arg[0],arg[1],arg[2],arg[3],arg[4]); else if (begin) result = FIN_N_BEGIN(arg[0],arg[1],arg[2],arg[3],arg[4]); --- 1047,1051 ---- case MATH_FINN: if (arg[0] == 0.0) ! result = FIN_N_ZERO(arg[1],arg[2],arg[3]); else if (begin) result = FIN_N_BEGIN(arg[0],arg[1],arg[2],arg[3],arg[4]); *************** *** 1036,1040 **** case MATH_FINFV: if (arg[0] == 0.0) ! result = FIN_FV_ZERO(arg[0],arg[1],arg[2],arg[3],arg[4]); else if (begin) result = FIN_FV_BEGIN(arg[0],arg[1],arg[2],arg[3],arg[4]); --- 1055,1059 ---- case MATH_FINFV: if (arg[0] == 0.0) ! result = FIN_FV_ZERO(arg[1],arg[2],arg[3]); else if (begin) result = FIN_FV_BEGIN(arg[0],arg[1],arg[2],arg[3],arg[4]); Index: display.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/display.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** display.cpp 2 Nov 2009 17:24:39 -0000 1.6 --- display.cpp 15 Dec 2009 21:37:44 -0000 1.7 *************** *** 184,202 **** Int16 i,j; TCHAR *result,*tmp; result = (TCHAR *) MemPtrNew(((dispPrefs.decPoints+15)*m->rows*m->cols + 10)*sizeof(TCHAR)); ! StrPrintF(result,_T("[")); for (i=0;i<m->rows;i++) { ! if (i) StrCat(result,_T(":")); ! StrCat(result,_T("[")); for (j=0;j<m->cols;j++) { ! if (j) StrCat(result,_T(":")); tmp = display_real(MATRIX(m,i,j)); ! StrCat(result,tmp); MemPtrFree(tmp); } ! StrCat(result,_T("]")); } ! StrCat(result,_T("]")); return result; } --- 184,205 ---- Int16 i,j; TCHAR *result,*tmp; + int index; result = (TCHAR *) MemPtrNew(((dispPrefs.decPoints+15)*m->rows*m->cols + 10)*sizeof(TCHAR)); ! index = StrPrintF(result,_T("[")); for (i=0;i<m->rows;i++) { ! if (i) ! StrCat(result+index,_T(":")); ! StrCat(result+index,_T("[")); for (j=0;j<m->cols;j++) { ! if (j) StrCat(result+index,_T(":")); tmp = display_real(MATRIX(m,i,j)); ! StrCat(result+index,tmp); MemPtrFree(tmp); + index += StrLen(result+index); } ! StrCat(result+index,_T("]")); } ! StrCat(result+index,_T("]")); return result; } *************** *** 243,247 **** ***********************************************************************/ TCHAR * ! display_default(Trpn rpn, Boolean complete) { TCHAR *result; --- 246,250 ---- ***********************************************************************/ TCHAR * ! display_default(Trpn rpn, Boolean complete, rpntype *resultType) { TCHAR *result; *************** *** 259,262 **** --- 262,267 ---- } + if (resultType) + *resultType = rpn.type; switch (rpn.type) { case integer: Index: konvert.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/konvert.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** konvert.cpp 2 Nov 2009 17:24:39 -0000 1.6 --- konvert.cpp 15 Dec 2009 21:37:44 -0000 1.7 *************** *** 160,163 **** --- 160,164 ---- {_T("atan2"),MATH_ATAN2,math_convcoord,2}, {_T("torad"),FUNC_RADIAN,convert_real_to_string,1}, + {_T("tograd"),FUNC_GRAD,convert_real_to_string,1}, {_T("togonio"),FUNC_GONIO,convert_cplx_to_string,1}, {_T("ipart"),MATH_TRUNC,math_round,1,true,true}, *************** *** 588,592 **** /* We compile the condition argument as ususal. The true and false ! * false arguments are stored as strings. They are compiled and * executed later in func_if(). This allows 'lazy evaluation' of * the if statement and recursion. --- 589,593 ---- /* We compile the condition argument as ususal. The true and false ! * arguments are stored as strings. They are compiled and * executed later in func_if(). This allows 'lazy evaluation' of * the if statement and recursion. *************** *** 601,605 **** } /* Now we have the condition argument, process it as normal */ ! lastchar = *ptr; *ptr = '\0'; if (!konvert_to_meq(buf, priority, &prmcnt1, _T(')'), err)) return 0; --- 602,607 ---- } /* Now we have the condition argument, process it as normal */ ! lastchar = *ptr; ! *ptr = _T('\0'); if (!konvert_to_meq(buf, priority, &prmcnt1, _T(')'), err)) return 0; Index: fp.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/fp.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** fp.cpp 25 Oct 2009 17:52:34 -0000 1.5 --- fp.cpp 15 Dec 2009 21:37:44 -0000 1.6 *************** *** 150,153 **** --- 150,154 ---- Tdisp_mode oldmode = dispPrefs.mode; dispPrefs.mode = newmode; + fp_reread_prefs(); return oldmode; } *************** *** 170,174 **** cvt_fltoa(TCHAR *strP,double value) { ! TCHAR *cP; TCHAR tmpstr[MAX_FP_NUMBER+3]; Int16 i,ichar; --- 171,175 ---- cvt_fltoa(TCHAR *strP,double value) { ! // TCHAR *cP; TCHAR tmpstr[MAX_FP_NUMBER+3]; Int16 i,ichar; *************** *** 179,183 **** } /* We convert the number backwards */ ! for (i=MAX_FP_NUMBER-2;i>=0;i--) { ichar = (Int16)fmod(value,BASE) + _T('0'); tmpstr[i] = ichar>_T('9')?ichar-_T('9')-1+_T('A'):ichar; --- 180,186 ---- } /* We convert the number backwards */ ! // Mapi: speeding things up. ! // for (i=MAX_FP_NUMBER-2;i>=0;i--) { ! for (i=MAX_FP_NUMBER-2 ; (i>=0)&&(value!=0.0) ; i--) { ichar = (Int16)fmod(value,BASE) + _T('0'); tmpstr[i] = ichar>_T('9')?ichar-_T('9')-1+_T('A'):ichar; *************** *** 188,195 **** tmpstr[MAX_FP_NUMBER-1] = _T('\0'); ! for( cP = tmpstr; *cP && (*cP == _T('0')); ) ! ++cP; ! ! StrCopy(strP,cP); } --- 191,199 ---- tmpstr[MAX_FP_NUMBER-1] = _T('\0'); ! // for( cP = tmpstr; *cP && (*cP == _T('0')); ) ! // ++cP; ! // ! // StrCopy(strP,cP); ! StrCopy(strP,tmpstr+i+1); } *************** *** 352,356 **** Int16 mydec = dispPrefs.decPoints - 1; /* Engineer mode selected */ ! // This loops at infinity when value = 0.0 //for (ex=0;fabs(value)<0.99999999 || (ex % 3);ex++,value*=BASE) ex = 0; --- 356,360 ---- Int16 mydec = dispPrefs.decPoints - 1; /* Engineer mode selected */ ! // Mapi: this loops at infinity when value = 0.0 ! Corrected. //for (ex=0;fabs(value)<0.99999999 || (ex % 3);ex++,value*=BASE) ex = 0; Index: integ.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/integ.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** integ.cpp 17 Oct 2009 13:48:34 -0000 1.1 --- integ.cpp 15 Dec 2009 21:37:44 -0000 1.2 *************** *** 620,624 **** } } else { /* funcnum = ZERO | VALUE */ ! /* partition the intrval to X parts and * try to find if the root is not in one of them */ --- 620,624 ---- } } else { /* funcnum = ZERO | VALUE */ ! /* partition the interval to X parts and * try to find if the root is not in one of them */ Index: txtask.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/txtask.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** txtask.cpp 2 Nov 2009 17:24:39 -0000 1.1 --- txtask.cpp 15 Dec 2009 21:37:44 -0000 1.2 *************** *** 69,73 **** err = rpn_eval_variable(&tmpitem, tmpitem); if (!err) ! text = display_default(tmpitem, true); rpn_delete(tmpitem); } else --- 69,73 ---- err = rpn_eval_variable(&tmpitem, tmpitem); if (!err) ! text = display_default(tmpitem, true, NULL); rpn_delete(tmpitem); } else *************** *** 77,81 **** param.defaultvalue = text; res = popupAskTxt(¶m); ! MemPtrFree(text); if (res) { --- 77,82 ---- param.defaultvalue = text; res = popupAskTxt(¶m); ! if (text) ! MemPtrFree(text); if (res) { |