|
From: Mapi B. <ma...@us...> - 2009-10-25 17:52:46
|
Update of /cvsroot/easycalc/PPCport/core/mlib In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv29338 Modified Files: complex.cpp fp.cpp funcs.cpp funcs.h Log Message: Functional, not much bugs should be left, still limited in function (no list, no matrix, no graph ..) Index: funcs.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/funcs.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** funcs.cpp 17 Oct 2009 13:48:34 -0000 1.5 --- funcs.cpp 25 Oct 2009 17:52:34 -0000 1.6 *************** *** 145,148 **** --- 145,161 ---- } + // Mapi: added Infinity + static CError inf_func(Trpn *rpn,double val) PARSER; + static CError + inf_func(Trpn *rpn,double val) + { + double x = 0.0; + + rpn->type=real; + rpn->u.realval=1.0/x; + rpn->allocsize = 0; + return c_noerror; + } + static CError rand_func(Trpn *rpn,double val) PARSER; static CError *************** *** 185,188 **** --- 198,202 ---- {_T("i"),i_func}, {_T("j"),i_func}, + {_T("Inf"),inf_func}, {_T("T"),dnum_func,1E12}, {_T("G"),dnum_func,1E9}, Index: funcs.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/funcs.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** funcs.h 17 Oct 2009 13:48:34 -0000 1.4 --- funcs.h 25 Oct 2009 17:52:34 -0000 1.5 *************** *** 43,47 **** #define MAX_RECURS 10 /* When the 'real' argument is zero */ ! #define IS_ZERO(x) (fabs(x)<1E-6) #define FUNC_EMPTY 0 --- 43,48 ---- #define MAX_RECURS 10 /* When the 'real' argument is zero */ ! //#define IS_ZERO(x) (fabs(x)<1E-6) ! #define IS_ZERO(x) (FlpIsZero1(x)) #define FUNC_EMPTY 0 Index: fp.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/fp.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** fp.cpp 17 Oct 2009 13:48:34 -0000 1.4 --- fp.cpp 25 Oct 2009 17:52:34 -0000 1.5 *************** *** 314,321 **** * ***********************************************************************/ ! void fp_print_double(TCHAR *strP,double value) PARSER; ! void ! fp_print_double(TCHAR *strP, double value) ! { Int16 ex; TCHAR tmpstr[MAX_FP_NUMBER*2]; --- 314,319 ---- * ***********************************************************************/ ! void fp_print_double (TCHAR *strP,double value) PARSER; ! void fp_print_double (TCHAR *strP, double value) { Int16 ex; TCHAR tmpstr[MAX_FP_NUMBER*2]; *************** *** 354,359 **** Int16 mydec = dispPrefs.decPoints - 1; /* Engineer mode selected */ ! for (ex=0;fabs(value)<0.99999999 || (ex % 3);ex++,value*=BASE) ! ; if (fabs(value) >= 100.0) --- 352,363 ---- 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; ! if (!FlpIsZero(value)) ! while ((fabs(value ) < 0.999999999999999) || (ex % 3)) { ! ex++; ! value *= BASE; ! } if (fabs(value) >= 100.0) Index: complex.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/complex.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** complex.cpp 17 Oct 2009 13:48:34 -0000 1.1 --- complex.cpp 25 Oct 2009 17:52:34 -0000 1.2 *************** *** 120,124 **** * z = xe^(iy) * z^w = (xe^(iy))^w = x^w*e^(iyw) = ! * = e^(w*ln(x))*e^(iyw) = w^(w*(ln(x)+yi)) * * PARAMETERS: 2 complex numbers --- 120,124 ---- * z = xe^(iy) * z^w = (xe^(iy))^w = x^w*e^(iyw) = ! * = e^(w*ln(x))*e^(iyw) = e^(w*(ln(x)+yi)) * * PARAMETERS: 2 complex numbers *************** *** 135,148 **** Complex tmp,result; ! gtmp=cplx_to_gon(base); ! tmp.real = log(gtmp.r); ! tmp.imag = gtmp.angle; ! tmp = cplx_multiply(expon,tmp); ! result.real = exp(tmp.real) * cos(tmp.imag); ! result.imag = exp(tmp.real) * sin(tmp.imag); ! return result; } --- 135,208 ---- Complex tmp,result; ! // If expon is integral and is within some bounds, use another computation method ! // which will be more precise. This is coming from free42. ! if (FlpIsZero(expon.imag) && (expon.real == floor(expon.real)) ! && (expon.real >= -2147483647.0) && (expon.real <= 2147483647.0)) { ! int w = (int) (expon.real); ! if (FlpIsZero(base.real) && FlpIsZero(base.imag)) { ! if (w < 0) { ! double tmp = 1.0; ! result.real = tmp / 0.0; // +infinity ! result.imag = 0.0; ! return (result); ! } else if (w > 0) { ! result.real = 0.0; ! result.imag = 0.0; ! return (result); ! } ! } ! if (w == 0) { ! result.real = 1.0; ! result.imag = 0.0; ! return (result); ! } ! double zr = base.real; ! double zi = base.imag; ! if (w < 0) { ! double h = _hypot(zr, zi); ! zr = zr / h / h; ! zi = (-zi) / h / h; ! w = -w; ! } ! double res_r = 1; ! double res_i = 0; ! double tmp; ! while (1) { ! if ((w & 1) != 0) { ! tmp = res_r * zr - res_i * zi; ! res_i = res_r * zi + res_i * zr; ! res_r = tmp; ! /* TODO: can one component be infinite while ! * the other is zero? If yes, how do we handle ! * that? ! */ ! if (isinf(res_r) && isinf(res_i)) ! break; ! if ((res_r == 0.0) && (res_i == 0.0)) ! break; ! } ! w >>= 1; ! if (w == 0) ! break; ! tmp = zr * zr - zi * zi; ! zi = 2 * zr * zi; ! zr = tmp; ! } ! result.real = res_r; ! result.imag = res_i; ! } else { ! gtmp=cplx_to_gon(base); ! tmp.real = log(gtmp.r); ! tmp.imag = gtmp.angle; ! tmp = cplx_multiply(expon,tmp); ! ! result.real = exp(tmp.real) * cos(tmp.imag); ! result.imag = exp(tmp.real) * sin(tmp.imag); ! } ! ! return result; } |