gcalctool r2127 - in trunk: . gcalctool



Author: rancell
Date: Thu Jul  3 10:17:10 2008
New Revision: 2127
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2127&view=rev

Log:
Applied third mp math tidy up patch from  Klaus Niederkrueger (Bug #524091)

Modified:
   trunk/ChangeLog
   trunk/gcalctool/ce_parser.y
   trunk/gcalctool/functions.c
   trunk/gcalctool/gtk.c
   trunk/gcalctool/lr_parser.y
   trunk/gcalctool/mp.c
   trunk/gcalctool/mp.h
   trunk/gcalctool/mpmath.c

Modified: trunk/gcalctool/ce_parser.y
==============================================================================
--- trunk/gcalctool/ce_parser.y	(original)
+++ trunk/gcalctool/ce_parser.y	Thu Jul  3 10:17:10 2008
@@ -225,7 +225,7 @@
 | tSQRT term %prec HIGH {mpsqrt($2, $$);}
 | tLN term %prec HIGH {mpln($2, $$);}
 | tRAND %prec HIGH {calc_rand($$);}
-| tABS term %prec HIGH {mpabs($2, $$);}
+| tABS term %prec HIGH {mp_abs($2, $$);}
 | tFRAC term %prec HIGH {mpcmf($2, $$);}
 | tINT term %prec HIGH {mpcmim($2, $$);}
 | tCHS term %prec HIGH {mpneg($2, $$);}

Modified: trunk/gcalctool/functions.c
==============================================================================
--- trunk/gcalctool/functions.c	(original)
+++ trunk/gcalctool/functions.c	Thu Jul  3 10:17:10 2008
@@ -261,7 +261,7 @@
                 result = display_solve(MPval);
                 switch (result) {
                     case 0:
-                        mpstr(MPval, e->ans);
+                        mp_set_from_mp(MPval, e->ans);
                         display_set_string("Ans");
                         cursor = -1;
                         break;
@@ -327,9 +327,9 @@
     if (v->current == KEY_CALCULATE &&
         v->ltr.old_cal_value == KEY_CALCULATE) {
         if (v->ltr.new_input) {
-            mpstr(v->MPlast_input, v->MPresult);
+            mp_set_from_mp(v->MPlast_input, v->MPresult);
         } else {
-            mpstr(v->MPlast_input, v->MPdisp_val);
+            mp_set_from_mp(v->MPlast_input, v->MPdisp_val);
         }
     }
 
@@ -352,7 +352,7 @@
         case KEY_ATAN:
         case KEY_ATANH:
         case -1:
-            mpstr(v->MPdisp_val, v->MPresult);
+            mp_set_from_mp(v->MPdisp_val, v->MPresult);
             break;
 
         case KEY_ADD:
@@ -429,10 +429,10 @@
 
     if (!(v->current == KEY_CALCULATE &&
           v->ltr.old_cal_value == KEY_CALCULATE)) {
-        mpstr(v->MPdisp_val, v->MPlast_input);
+        mp_set_from_mp(v->MPdisp_val, v->MPlast_input);
     }
 
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
     if (v->current != KEY_CALCULATE) {
         v->ltr.cur_op = v->current;
     }
@@ -446,7 +446,7 @@
 {
     calc_trigfunc(sin_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -455,7 +455,7 @@
 {
     calc_trigfunc(sinh_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -464,7 +464,7 @@
 {
     calc_trigfunc(asin_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -473,7 +473,7 @@
 {
     calc_trigfunc(asinh_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -482,7 +482,7 @@
 {
     calc_trigfunc(cos_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -491,7 +491,7 @@
 {
     calc_trigfunc(cosh_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -500,7 +500,7 @@
 {
     calc_trigfunc(acos_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -509,7 +509,7 @@
 {
     calc_trigfunc(acosh_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -518,7 +518,7 @@
 {
     calc_trigfunc(tan_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -527,7 +527,7 @@
 {
     calc_trigfunc(tanh_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -536,7 +536,7 @@
 {
     calc_trigfunc(atan_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -545,7 +545,7 @@
 {
     calc_trigfunc(atanh_t, v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -554,7 +554,7 @@
 {
     calc_percent(v->MPdisp_val, v->MPresult);
     display_set_number(v->MPresult);
-    mpstr(v->MPresult, v->MPdisp_val);
+    mp_set_from_mp(v->MPresult, v->MPdisp_val);
 }
 
 
@@ -601,7 +601,7 @@
                 ui_set_statusbar(_("No sane value to convert"),
                                  "gtk-dialog-error");
             } else {
-                mpstr(MP, e->ans);
+                mp_set_from_mp(MP, e->ans);
                 display_set_string("Ans");
             }
             v->base = b;
@@ -629,7 +629,7 @@
     assert(index <= 9);
 
     MPval = v->MPcon_vals[index];
-    mpstr(MPval, v->MPdisp_val);
+    mp_set_from_mp(MPval, v->MPdisp_val);
     v->ltr.new_input = 1;
     syntaxdep_show_display();
 }
@@ -687,9 +687,9 @@
 
     switch (v->syntax) {
         case NPA:
-            mpstr(v->MPdisp_val, MPtemp);
-            mpstr(v->MPmvals[index], v->MPdisp_val);
-            mpstr(MPtemp, v->MPmvals[index]);
+            mp_set_from_mp(v->MPdisp_val, MPtemp);
+            mp_set_from_mp(v->MPmvals[index], v->MPdisp_val);
+            mp_set_from_mp(MPtemp, v->MPmvals[index]);
             ui_make_registers();
             break;
 
@@ -700,9 +700,9 @@
                 ui_set_statusbar(_("No sane value to store"),
                                  "gtk-dialog-error");
             } else {
-                mpstr(v->MPmvals[index], MPtemp);
-                mpstr(MPexpr, v->MPmvals[index]);
-                mpstr(MPtemp, e->ans);
+                mp_set_from_mp(v->MPmvals[index], MPtemp);
+                mp_set_from_mp(MPexpr, v->MPmvals[index]);
+                mp_set_from_mp(MPtemp, e->ans);
                 display_set_string("Ans");
                 display_refresh(-1);
                 ui_make_registers();
@@ -757,7 +757,7 @@
  *        order to check this.
  */
 
-    mpstr(MPval, MPa);
+    mp_set_from_mp(MPval, MPa);
     mpcmim(MPval, MP1);
     mp_set_from_integer(0, MP2);
     if (mp_is_equal(MPval, MP1)
@@ -784,7 +784,7 @@
     } else {
         matherr((struct exception *) NULL);
     }
-    mpstr(MPa, MPres);
+    mp_set_from_mp(MPa, MPres);
 }
 
 
@@ -838,7 +838,7 @@
             break;
 
         case KEY_E_POW_X:
-            mpstr(s, MP1);
+            mp_set_from_mp(s, MP1);
             mpexp(MP1, t);
             break;
 
@@ -847,7 +847,7 @@
             break;
 
         case KEY_NATURAL_LOGARITHM:
-            mpstr(s, MP1);
+            mp_set_from_mp(s, MP1);
             mpln(MP1, t);
             break;
 
@@ -864,7 +864,7 @@
             break;
 
         case KEY_SQUARE_ROOT:
-            mpstr(s, MP1);
+            mp_set_from_mp(s, MP1);
             mpsqrt(MP1, t);
             break;
 
@@ -878,11 +878,11 @@
 
         case KEY_FACTORIAL:
             do_factorial(s, MP1);
-            mpstr(MP1, t);
+            mp_set_from_mp(MP1, t);
             break;
 
         case KEY_SQUARE:
-            mpstr(s, MP1);
+            mp_set_from_mp(s, MP1);
             mpmul(MP1, MP1, t);
             break;
 
@@ -954,7 +954,7 @@
                 ui_set_statusbar(_("No sane value to convert"),
                                  "gtk-dialog-error");
             } else {
-                mpstr(MP, e->ans);
+                mp_set_from_mp(MP, e->ans);
                 display_set_string("Ans");
                 ui_make_registers();
             }
@@ -1019,7 +1019,7 @@
 {
     switch (v->syntax) {
         case NPA:
-            mpstr(v->MPdisp_val, v->MPmvals[index]);
+            mp_set_from_mp(v->MPdisp_val, v->MPmvals[index]);
             break;
 
         case EXPRS:
@@ -1046,7 +1046,7 @@
 do_sto_reg(int reg, int value[MP_SIZE])
 {
     if ((reg >= 0) && (reg <= 10)) {
-        mpstr(value, v->MPmvals[reg]);
+        mp_set_from_mp(value, v->MPmvals[reg]);
         return(0);
     } else {
         return(-EINVAL);
@@ -1057,7 +1057,7 @@
 void
 do_rcl(int index)
 {
-    mpstr(v->MPmvals[index], v->MPdisp_val);
+    mp_set_from_mp(v->MPmvals[index], v->MPdisp_val);
     v->ltr.new_input = 1;
     syntaxdep_show_display();
 }
@@ -1072,7 +1072,7 @@
 do_rcl_reg(int reg, int value[MP_SIZE])
 {
     if ((reg >= 0) && (reg <= 10)) {
-        mpstr(v->MPmvals[reg], value);
+        mp_set_from_mp(v->MPmvals[reg], value);
         return(0);
     } else {
         return(-EINVAL);
@@ -1122,17 +1122,17 @@
 
     switch (v->current) {
         case KEY_ABSOLUTE_VALUE:
-            mpstr(num, MP1);
-            mpabs(MP1, num);
+            mp_set_from_mp(num, MP1);
+            mp_abs(MP1, num);
             break;
 
         case KEY_FRACTION:
-            mpstr(num, MP1);
+            mp_set_from_mp(num, MP1);
             mpcmf(MP1, num);
             break;
 
         case KEY_INTEGER:
-            mpstr(num, MP1);
+            mp_set_from_mp(num, MP1);
             mpcmim(MP1, num);
             break;
     }
@@ -1170,7 +1170,7 @@
             dval = setbool(temp);
             mp_set_from_double(dval, v->MPdisp_val);
             display_set_number(v->MPdisp_val);
-            mpstr(v->MPdisp_val, v->MPlast_input);
+            mp_set_from_mp(v->MPdisp_val, v->MPlast_input);
             break;
 
         case EXPRS:

Modified: trunk/gcalctool/gtk.c
==============================================================================
--- trunk/gcalctool/gtk.c	(original)
+++ trunk/gcalctool/gtk.c	Thu Jul  3 10:17:10 2008
@@ -1753,7 +1753,7 @@
         case EXPRS: {
             int ret = display_is_usable_number(e->ans);
             assert(!ret);
-            mpstr(e->ans, MP1);
+            mp_set_from_mp(e->ans, MP1);
         }
         break;
         default:

Modified: trunk/gcalctool/lr_parser.y
==============================================================================
--- trunk/gcalctool/lr_parser.y	(original)
+++ trunk/gcalctool/lr_parser.y	Thu Jul  3 10:17:10 2008
@@ -162,8 +162,8 @@
 | term tSQRT {mpsqrt($1, $$);}
 | tLN parenthesis {mpln($2, $$);}
 | term tLN {mpln($1, $$);}
-| tABS parenthesis {mpabs($2, $$);}
-| term tABS {mpabs($1, $$);}
+| tABS parenthesis {mp_abs($2, $$);}
+| term tABS {mp_abs($1, $$);}
 | tFRAC parenthesis {mpcmf($2, $$);}
 | term tFRAC {mpcmf($1, $$);}
 | tINT parenthesis {mpcmim($2, $$);}

Modified: trunk/gcalctool/mp.c
==============================================================================
--- trunk/gcalctool/mp.c	(original)
+++ trunk/gcalctool/mp.c	Thu Jul  3 10:17:10 2008
@@ -106,16 +106,13 @@
 
 
 void
-mpabs(int *x, int *y)
+mp_abs(const int *x, int *y)
 {
 
 /* SETS Y = ABS(X) FOR MP NUMBERS X AND Y */
 
-    --y;                      /* Parameter adjustments */
-    --x;
-
-    mpstr(&x[1], &y[1]);
-    y[1] = C_abs(y[1]);
+    mp_set_from_mp(x, y);
+    y[0] = C_abs(y[0]);
 }
 
 
@@ -164,7 +161,7 @@
 /* X = 0 OR NEGLIGIBLE, SO RESULT = +-Y */
 
 L10:
-    mpstr(&y[1], &z[1]);
+    mp_set_from_mp(&y[1], &z[1]);
     z[1] = y1[1];
     return;
 
@@ -174,7 +171,7 @@
 /* Y = 0 OR NEGLIGIBLE, SO RESULT = X */
 
 L30:
-    mpstr(&x[1], &z[1]);
+    mp_set_from_mp(&x[1], &z[1]);
     return;
 
 /* COMPARE SIGNS */
@@ -478,7 +475,7 @@
 
 /* SET ADDITIVE TERM TO X */
 
-    mpstr(&y[1], &MP.r[i2 - 1]);
+    mp_set_from_mp(&y[1], &MP.r[i2 - 1]);
     i = 1;
     id = 0;
 
@@ -582,7 +579,7 @@
 L40:
     i2 = i3 - (MP.t + 2);
     mp_set_from_integer(1, &MP.r[i2 - 1]);
-    mpstr(&MP.r[i2 - 1], &MP.r[i3 - 1]);
+    mp_set_from_mp(&MP.r[i2 - 1], &MP.r[i3 - 1]);
     mpsub(&MP.r[i2 - 1], &x[1], &MP.r[i2 - 1]);
     mpadd(&MP.r[i3 - 1], &x[1], &MP.r[i3 - 1]);
     mpmul(&MP.r[i2 - 1], &MP.r[i3 - 1], &MP.r[i3 - 1]);
@@ -625,7 +622,7 @@
     return;
 
 L10:
-    mpstr(&x[1], &MP.r[i3 - 1]);
+    mp_set_from_mp(&x[1], &MP.r[i3 - 1]);
     ie = C_abs(x[2]);
     if (ie <= 2) mpcmr(&x[1], &rx);
 
@@ -650,7 +647,7 @@
 /* USE POWER SERIES NOW ARGUMENT IN (-0.5, 0.5) */
 
 L30:
-    mpstr(&MP.r[i3 - 1], &y[1]);
+    mp_set_from_mp(&MP.r[i3 - 1], &y[1]);
     mpmul(&MP.r[i3 - 1], &MP.r[i3 - 1], &MP.r[i2 - 1]);
     i = 1;
     ts = MP.t;
@@ -1052,7 +1049,7 @@
 
     if (x2 > 0) goto L30;
 
-    mpstr(&x[1], &y[1]);
+    mp_set_from_mp(&x[1], &y[1]);
     return;
 
 /* CLEAR ACCUMULATOR */
@@ -1170,7 +1167,7 @@
     --x;
 
     mpchk(&c__1, &c__4);
-    mpstr(&x[1], &y[1]);
+    mp_set_from_mp(&x[1], &y[1]);
     if (y[1] == 0) {
         return;
     }
@@ -1441,7 +1438,7 @@
 
 /* SEE IF ABS(X) .LE. 1 */
 
-    mpabs(&x[1], &y[1]);
+    mp_abs(&x[1], &y[1]);
     if (mpcmpi(&y[1], &c__1) <= 0) goto L20;
 
 /*  HERE ABS(X) .GT. 1 SO USE COS(X) = SIN(PI/2 - ABS(X)),
@@ -1487,7 +1484,7 @@
 L10:
     mpchk(&c__5, &c__12);
     i2 = (MP.t << 2) + 11;
-    mpabs(&x[1], &MP.r[i2 - 1]);
+    mp_abs(&x[1], &MP.r[i2 - 1]);
 
 /*  IF ABS(X) TOO LARGE MPEXP WILL PRINT ERROR MESSAGE
  *  INCREASE M TO AVOID OVERFLOW WHEN COSH(X) REPRESENTABLE
@@ -1791,7 +1788,7 @@
 /* CHECK FOR DIVISION BY B */
 
     if (j != MP.b) goto L50;
-    mpstr(&x[1], &z[1]);
+    mp_set_from_mp(&x[1], &z[1]);
     if (re <= -MP.m) goto L240;
     z[1] = rs;
     z[2] = re - 1;
@@ -1801,7 +1798,7 @@
 
 L50:
     if (j != 1) goto L60;
-    mpstr(&x[1], &z[1]);
+    mp_set_from_mp(&x[1], &z[1]);
     z[1] = rs;
     return;
 
@@ -2053,7 +2050,7 @@
 /* SAVE SIGN AND WORK WITH ABS(X) */
 
     xs = x[1];
-    mpabs(&x[1], &MP.r[i3 - 1]);
+    mp_abs(&x[1], &MP.r[i3 - 1]);
 
 /*  IF ABS(X) .GT. M POSSIBLE THAT INT(X) OVERFLOWS,
  *  SO DIVIDE BY 32.
@@ -2211,7 +2208,7 @@
     goto L10;
 
 L40:
-    mpstr(&x[1], &MP.r[i2 - 1]);
+    mp_set_from_mp(&x[1], &MP.r[i2 - 1]);
     rlb = log((float) MP.b);
 
 /* COMPUTE APPROXIMATELY OPTIMAL Q (AND DIVIDE X BY 2**Q) */
@@ -2234,8 +2231,8 @@
 
 L60:
     if (MP.r[i2 - 1] == 0) goto L10;
-    mpstr(&MP.r[i2 - 1], &y[1]);
-    mpstr(&MP.r[i2 - 1], &MP.r[i3 - 1]);
+    mp_set_from_mp(&MP.r[i2 - 1], &y[1]);
+    mp_set_from_mp(&MP.r[i2 - 1], &MP.r[i3 - 1]);
     i = 1;
     ts = MP.t;
 
@@ -2412,7 +2409,7 @@
 /* MOVE X TO LOCAL STORAGE */
 
 L20:
-    mpstr(&x[1], &MP.r[i2 - 1]);
+    mp_set_from_mp(&x[1], &MP.r[i2 - 1]);
     y[1] = 0;
     k = 0;
 
@@ -2513,7 +2510,7 @@
 
 L30:
     ts = MP.t;
-    mpstr(&x[1], &MP.r[i3 - 1]);
+    mp_set_from_mp(&x[1], &MP.r[i3 - 1]);
     mpdivi(&x[1], &c__4, &MP.r[i2 - 1]);
     mpaddq(&MP.r[i2 - 1], &c_n1, &c__3, &MP.r[i2 - 1]);
     mpmul(&x[1], &MP.r[i2 - 1], &MP.r[i2 - 1]);
@@ -2807,7 +2804,7 @@
     return;
 
 L40:
-    mpstr(&x[1], &z[1]);
+    mp_set_from_mp(&x[1], &z[1]);
     z[1] = rs;
     z[2] = x[2] + 1;
     return;
@@ -2991,7 +2988,7 @@
     --y;             /* Parameter adjustments */
     --x;
 
-    mpstr(&x[1], &y[1]);
+    mp_set_from_mp(&x[1], &y[1]);
     y[1] = -y[1];
 }
 
@@ -3276,12 +3273,12 @@
 /* MOVE X */
 
 L60:
-    mpstr(&x[1], &y[1]);
+    mp_set_from_mp(&x[1], &y[1]);
 
 /* IF N .LT. 0 FORM RECIPROCAL */
 
     if (*n < 0) mprec(&y[1], &y[1]);
-    mpstr(&y[1], &MP.r[i2 - 1]);
+    mp_set_from_mp(&y[1], &MP.r[i2 - 1]);
 
 /* SET PRODUCT TERM TO ONE */
 
@@ -3489,7 +3486,7 @@
 
 L70:
     MP.t = ts;
-    mpstr(&MP.r[i2 - 1], &y[1]);
+    mp_set_from_mp(&MP.r[i2 - 1], &y[1]);
 
 /* RESTORE M AND CHECK FOR OVERFLOW (UNDERFLOW IMPOSSIBLE) */
 
@@ -3531,7 +3528,7 @@
 
     mpchk(&c__4, &c__10);
     if (*n != 1) goto L10;
-    mpstr(&x[1], &y[1]);
+    mp_set_from_mp(&x[1], &y[1]);
     return;
 
 L10:
@@ -3703,7 +3700,7 @@
     return;
 
 L170:
-    mpstr(&MP.r[i2 - 1], &y[1]);
+    mp_set_from_mp(&MP.r[i2 - 1], &y[1]);
 }
 
 
@@ -3846,7 +3843,7 @@
     ie = C_abs(x[2]);
     if (ie <= 2) mpcmr(&x[1], &rx);
 
-    mpabs(&x[1], &MP.r[i2 - 1]);
+    mp_abs(&x[1], &MP.r[i2 - 1]);
 
 /* USE MPSIN1 IF ABS(X) .LE. 1 */
 
@@ -3978,14 +3975,14 @@
 
 L40:
     if (*is == 0) mp_set_from_integer(1, &MP.r[i2 - 1]);
-    if (*is != 0) mpstr(&x[1], &MP.r[i2 - 1]);
+    if (*is != 0) mp_set_from_mp(&x[1], &MP.r[i2 - 1]);
 
     y[1] = 0;
     i = 1;
     ts = MP.t;
     if (*is == 0) goto L50;
 
-    mpstr(&MP.r[i2 - 1], &y[1]);
+    mp_set_from_mp(&MP.r[i2 - 1], &y[1]);
     i = 2;
 
 /* POWER SERIES LOOP.  REDUCE T IF POSSIBLE */
@@ -4057,7 +4054,7 @@
 
 /* WORK WITH ABS(X) */
 
-    mpabs(&x[1], &MP.r[i3 - 1]);
+    mp_abs(&x[1], &MP.r[i3 - 1]);
     if (MP.r[i3] <= 0) goto L20;
 
 /*  HERE ABS(X) .GE. 1, IF TOO LARGE MPEXP GIVES ERROR MESSAGE
@@ -4138,40 +4135,23 @@
 
 
 void
-mpstr(int *x, int *y)
+mp_set_from_mp(const int *x, int *y)
 {
-    int i__1;
-
-    static int i, j, t2;
 
 /*  SETS Y = X FOR MP X AND Y.
  *  SEE IF X AND Y HAVE THE SAME ADDRESS (THEY OFTEN DO)
  */
 
-    --y;                /* Parameter adjustments */
-    --x;
-
-    j = x[1];
-    y[1] = j + 1;
-    if (j == x[1]) goto L10;
+/* HERE X AND Y MUST HAVE THE SAME ADDRESS */    
+    if (x == y) return;
 
-/* HERE X(1) AND Y(1) MUST HAVE THE SAME ADDRESS */
-
-    x[1] = j;
-    return;
-
-/* HERE X(1) AND Y(1) HAVE DIFFERENT ADDRESSES */
-
-L10:
-    y[1] = j;
-
-/* NO NEED TO MOVE X(2), ... IF X(1) = 0 */
-
-    if (j == 0) return;
+/* NO NEED TO COPY X[1],X[2],... IF X[0] == 0 */
+    if (x[0] == 0) {
+      y[0] = 0;
+      return;
+    }
 
-    t2 = MP.t + 2;
-    i__1 = t2;
-    for (i = 2; i <= i__1; ++i) y[i] = x[i];
+    memcpy (y, x, (MP.t + 2)*sizeof(int));
 }
 
 
@@ -4223,7 +4203,7 @@
 /* SAVE SIGN AND WORK WITH ABS(X) */
 
     xs = x[1];
-    mpabs(&x[1], &MP.r[i2 - 1]);
+    mp_abs(&x[1], &MP.r[i2 - 1]);
 
 /* SEE IF ABS(X) SO LARGE THAT RESULT IS +-1 */
 

Modified: trunk/gcalctool/mp.h
==============================================================================
--- trunk/gcalctool/mp.h	(original)
+++ trunk/gcalctool/mp.h	Thu Jul  3 10:17:10 2008
@@ -36,8 +36,10 @@
 int    mp_cast_to_int(const int *);
 void   mp_set_from_double(double, int *);
 void   mp_set_from_integer(int, int *);
+void   mp_set_from_mp(const int *, int *);
+
+void mp_abs(const int *, int *);
 
-void mpabs(int *, int *);
 void mpadd(int *, int *, int *);
 void mpaddi(int *, int *, int *);
 void mpasin(int *, int *);
@@ -60,7 +62,6 @@
 void mpsin(int *, int *);
 void mpsinh(int *, int *);
 void mpsqrt(int *, int *);
-void mpstr(int *, int *);
 void mpsub(int *, int *, int *);
 void mptanh(int *, int *);
 

Modified: trunk/gcalctool/mpmath.c
==============================================================================
--- trunk/gcalctool/mpmath.c	(original)
+++ trunk/gcalctool/mpmath.c	Thu Jul  3 10:17:10 2008
@@ -147,7 +147,7 @@
     int MP2[MP_SIZE];
 
     mp_set_from_integer(1, MP1);
-    mpstr(s1, MP2);
+    mp_set_from_mp(s1, MP2);
     mpdiv(MP1, MP2, t1);
 }
 
@@ -276,7 +276,7 @@
         mp_set_from_integer(200, MP1);
         mpdiv(MP2, MP1, t1);
     } else {
-        mpstr(s1, t1);
+        mp_set_from_mp(s1, t1);
     }
 }
 
@@ -296,7 +296,7 @@
             break;
 
         case RAD:
-            mpstr(s1, t1);
+            mp_set_from_mp(s1, t1);
             break;
 
         case GRAD:
@@ -345,14 +345,14 @@
 
     if (mp_is_greater_than(MPx, MP1) || mp_is_less_than(MPx, MPn1)) {
         doerr(_("Error"));
-        mpstr(MP0, MPretval);
+        mp_set_from_mp(MP0, MPretval);
     } else if (mp_is_equal(MPx, MP0)) {
         val = 2;
         mpdivi(MPpi, &val, MPretval);
     } else if (mp_is_equal(MPx, MP1)) {
-        mpstr(MP0, MPretval);
+        mp_set_from_mp(MP0, MPretval);
     } else if (mp_is_equal(MPx, MPn1)) {
-        mpstr(MPpi, MPretval);
+        mp_set_from_mp(MPpi, MPretval);
     } else { 
         mpmul(MPx, MPx, MP2);
         mpsub(MP1, MP2, MP2);
@@ -360,7 +360,7 @@
         mpdiv(MP2, MPx, MP2);
         mpatan(MP2, MPy);
         if (mp_is_greater_than(MPx, MP0)) {
-            mpstr(MPy, MPretval);
+            mp_set_from_mp(MPy, MPretval);
         } else {
             mpadd(MPy, MPpi, MPretval);
         }
@@ -433,7 +433,7 @@
 
     if (mp_is_greater_equal(MPx, MP1) || mp_is_less_equal(MPx, MPn1)) {
         doerr(_("Error"));
-        mpstr(MP0, MPretval);
+        mp_set_from_mp(MP0, MPretval);
     } else {
         mpadd(MP1, MPx, MP2);
         mpsub(MP1, MPx, MP3);
@@ -515,7 +515,7 @@
         val = 2;
         mpmuli(MP1, &val, MP2);
         mpdiv(MP2, v->MPmvals[2], t);
-        mpstr(MPbv, MP1);
+        mp_set_from_mp(MPbv, MP1);
         mpadd(MP1, t, MPbv); /* TODO: why result is MPbv, for next loop? */
     }
 }
@@ -756,7 +756,7 @@
     if (!is_integer(MPnum)) {
         return 0;
     }
-    mpabs(MPnum, MP1);
+    mp_abs(MPnum, MP1);
     return mp_is_equal(MPnum, MP1);
 }
 
@@ -765,7 +765,7 @@
 {
     int MP1[MP_SIZE];
     
-    mpstr(s, MP1);
+    mp_set_from_mp(s, MP1);
     mpexp(MP1, t);
 }
 
@@ -847,7 +847,7 @@
     int dval, i;
  
     optr = target;
-    mpabs(MPnumber, MPval);
+    mp_abs(MPnumber, MPval);
     mp_set_from_integer(0, MP1);
     if (mp_is_less_than(MPnumber, MP1)) {
         *optr++ = '-';
@@ -929,12 +929,12 @@
         eng = 1;
     }
     optr = target;
-    mpabs(MPnumber, MPval);
+    mp_abs(MPnumber, MPval);
     mp_set_from_integer(0, MP1);
     if (mp_is_less_than(MPnumber, MP1)) {
         *optr++ = '-';
     }
-    mpstr(MPval, MPmant);
+    mp_set_from_mp(MPval, MPmant);
 
     mp_set_from_integer(basevals[base], MP1base);
     n = 3;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]