gcalctool r2110 - in trunk: . gcalctool
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2110 - in trunk: . gcalctool
- Date: Sat, 14 Jun 2008 06:48:24 +0000 (UTC)
Author: rancell
Date: Sat Jun 14 06:48:24 2008
New Revision: 2110
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2110&view=rev
Log:
Applied second mp math tidy up patch from Klaus Niederkrueger (Bug #524091)
Modified:
trunk/ChangeLog
trunk/gcalctool/calctool.c
trunk/gcalctool/ce_parser.y
trunk/gcalctool/display.c
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/calctool.c
==============================================================================
--- trunk/gcalctool/calctool.c (original)
+++ trunk/gcalctool/calctool.c Sat Jun 14 06:48:24 2008
@@ -682,7 +682,7 @@
static void
init_state(void)
{
- int acc, i, n, size;
+ int acc, i, size;
v->accuracy = DEFAULT_ACCURACY;
v->show_zeroes = FALSE; /* Don't show trailing zeroes. */
@@ -712,9 +712,8 @@
init_constant(8, "0.948"); /* Kjoules <=> BTU's. */
init_constant(9, "0.0610"); /* cms3 <=> inches3. */
- n = 0;
for (i = 0; i < MAX_REGISTERS; i++) {
- mpcim(&n, v->MPmvals[i]);
+ mp_set_from_integer(0, v->MPmvals[i]);
}
}
Modified: trunk/gcalctool/ce_parser.y
==============================================================================
--- trunk/gcalctool/ce_parser.y (original)
+++ trunk/gcalctool/ce_parser.y Sat Jun 14 06:48:24 2008
@@ -127,13 +127,11 @@
display_set_number(v->MPdisp_val);
}
| value '=' tSTO '(' tNUMBER ')' {
- int val;
- mpcmi($5, &val);
+ int val = mp_cast_to_int($5);
do_sto_reg(val, $1);
}
| value tSTO '(' tNUMBER ')' {
- int val;
- mpcmi($4, &val);
+ int val = mp_cast_to_int($4);
do_sto_reg(val, $1);
}
| tCLR {
@@ -261,8 +259,7 @@
rcl:
tRCL '(' tNUMBER ')' {
- int val;
- mpcmi($3, &val);
+ int val = mp_cast_to_int($3);
do_rcl_reg(val, $$);
}
;
Modified: trunk/gcalctool/display.c
==============================================================================
--- trunk/gcalctool/display.c (original)
+++ trunk/gcalctool/display.c Sat Jun 14 06:48:24 2008
@@ -180,7 +180,7 @@
case NPA:
v->ltr.pointed = 0;
v->ltr.toclear = 1;
- do_zero(v->MPdisp_val);
+ mp_set_from_integer(0, v->MPdisp_val);
display_set_number(v->MPdisp_val);
if (initialise == TRUE) {
@@ -206,9 +206,9 @@
v->error = 0; /* Currently no display error. */
v->ltr.cur_op = -1; /* No arithmetic operator defined yet. */
v->ltr.old_cal_value = -1;
- do_zero(v->MPresult); /* No previous result yet. */
- do_zero(v->MPdisp_val);
- do_zero(v->MPlast_input);
+ mp_set_from_integer(0, v->MPresult); /* No previous result yet. */
+ mp_set_from_integer(0, v->MPdisp_val);
+ mp_set_from_integer(0, v->MPlast_input);
v->ltr.new_input = 1; /* Value zero is on calculator display */
@@ -240,7 +240,7 @@
case KEY_CLEAR:
v->ltr.noparens = 0;
v->ltr.cur_op = -1;
- do_zero(v->MPdisp_val);
+ mp_set_from_integer(0, v->MPdisp_val);
display_set_number(v->MPdisp_val);
return;
case KEY_BACKSPACE:
@@ -523,7 +523,7 @@
case EXPRS:
e = get_state();
if (display_is_empty()) {
- do_zero(MP_reg);
+ mp_set_from_integer(0, MP_reg);
make_number(x, MAX_LOCALIZED, MP_reg, v->base, FALSE);
str = x;
} else {
Modified: trunk/gcalctool/functions.c
==============================================================================
--- trunk/gcalctool/functions.c (original)
+++ trunk/gcalctool/functions.c Sat Jun 14 06:48:24 2008
@@ -381,9 +381,10 @@
mpmul(MP1, v->MPdisp_val, MP2);
mpsub(v->MPresult, MP2, v->MPresult);
- do_zero(MP1);
- if ((mplt(v->MPdisp_val, MP1) && mpgt(v->MPresult, MP1)) ||
- mplt(v->MPresult, MP1)) {
+ mp_set_from_integer(0, MP1);
+ if ((mp_is_less_than(v->MPdisp_val, MP1)
+ && mp_is_greater_than(v->MPresult, MP1)) ||
+ mp_is_less_than(v->MPresult, MP1)) {
mpadd(v->MPresult, v->MPdisp_val, v->MPresult);
}
}
@@ -394,31 +395,31 @@
break;
case KEY_AND:
- mpcmd(v->MPresult, &dres);
- mpcmd(v->MPdisp_val, &dval);
+ dres = mp_cast_to_double(v->MPresult);
+ dval = mp_cast_to_double(v->MPdisp_val);
dres = setbool(ibool(dres) & ibool(dval));
- mpcdm(&dres, v->MPresult);
+ mp_set_from_double(dres, v->MPresult);
break;
case KEY_OR:
- mpcmd(v->MPresult, &dres);
- mpcmd(v->MPdisp_val, &dval);
+ dres = mp_cast_to_double(v->MPresult);
+ dval = mp_cast_to_double(v->MPdisp_val);
dres = setbool(ibool(dres) | ibool(dval));
- mpcdm(&dres, v->MPresult);
+ mp_set_from_double(dres, v->MPresult);
break;
case KEY_XOR:
- mpcmd(v->MPresult, &dres);
- mpcmd(v->MPdisp_val, &dval);
+ dres = mp_cast_to_double(v->MPresult);
+ dval = mp_cast_to_double(v->MPdisp_val);
dres = setbool(ibool(dres) ^ ibool(dval));
- mpcdm(&dres, v->MPresult);
+ mp_set_from_double(dres, v->MPresult);
break;
case KEY_XNOR:
- mpcmd(v->MPresult, &dres);
- mpcmd(v->MPdisp_val, &dval);
+ dres = mp_cast_to_double(v->MPresult);
+ dval = mp_cast_to_double(v->MPdisp_val);
dres = setbool(~ibool(dres) ^ ibool(dval));
- mpcdm(&dres, v->MPresult);
+ mp_set_from_double(dres, v->MPresult);
default:
break;
@@ -758,21 +759,21 @@
mpstr(MPval, MPa);
mpcmim(MPval, MP1);
- do_zero(MP2);
- if (mpeq(MPval, MP1) && mpge(MPval, MP2)) { /* Only positive integers. */
- i = 1;
- if (mpeq(MP1, MP2)) { /* Special case for 0! */
- mpcim(&i, MPres);
+ mp_set_from_integer(0, MP2);
+ if (mp_is_equal(MPval, MP1)
+ && mp_is_equal(MPval, MP2)) { /* Only positive integers. */
+ if (mp_is_equal(MP1, MP2)) { /* Special case for 0! */
+ mp_set_from_integer(1, MPres);
return;
}
- mpcim(&i, MPa);
- mpcmi(MP1, &i);
+ mp_set_from_integer(1, MPa);
+ i = mp_cast_to_int(MP1);
if (!i) {
matherr((struct exception *) NULL);
} else {
while (i > 0) {
mpmuli(MPa, &i, MPa);
- mpcmd(MPa, &val);
+ val = mp_cast_to_double(MPa);
if (v->error) {
mperr();
return;
@@ -1157,7 +1158,7 @@
switch (v->syntax) {
case NPA:
MPstr_to_num(v->display, v->base, MPtemp);
- mpcmd(MPtemp, &dval);
+ dval = mp_cast_to_double(MPtemp);
temp = ibool(dval);
if (count < 0) {
@@ -1167,7 +1168,7 @@
}
dval = setbool(temp);
- mpcdm(&dval, v->MPdisp_val);
+ mp_set_from_double(dval, v->MPdisp_val);
display_set_number(v->MPdisp_val);
mpstr(v->MPdisp_val, v->MPlast_input);
break;
Modified: trunk/gcalctool/gtk.c
==============================================================================
--- trunk/gcalctool/gtk.c (original)
+++ trunk/gcalctool/gtk.c Sat Jun 14 06:48:24 2008
@@ -891,7 +891,7 @@
case NPA:
MPstr_to_num(v->display, v->base, MP1);
mpcmim(MP1, MP2);
- if (mpeq(MP1, MP2)) {
+ if (mp_is_equal(MP1, MP2)) {
int toclear = (v->current == KEY_CLEAR_ENTRY)
? TRUE : FALSE;
@@ -1226,12 +1226,10 @@
aframe_response_cb(GtkWidget *dialog, gint response_id)
{
char *ch;
- int val;
if (response_id == GTK_RESPONSE_OK) {
ch = (char *) gtk_entry_get_text(GTK_ENTRY(X->aframe_ch));
- val = ch[0];
- mpcim(&val, v->MPdisp_val);
+ mp_set_from_integer(ch[0], v->MPdisp_val);
display_set_number(v->MPdisp_val);
}
@@ -1733,7 +1731,7 @@
assert(FALSE);
}
- mpcmd(MP1, &number);
+ number = mp_cast_to_double(MP1);
lval = (long long) number;
if (lval & (1LL << n)) {
@@ -1747,11 +1745,11 @@
switch (v->syntax) {
case NPA:
- mpcdm(&number, v->MPdisp_val);
+ mp_set_from_double(number, v->MPdisp_val);
display_set_number(v->MPdisp_val);
break;
case EXPRS:
- mpcdm(&number, e->ans);
+ mp_set_from_double(number, e->ans);
display_set_string("Ans");
display_refresh(-1);
break;
Modified: trunk/gcalctool/lr_parser.y
==============================================================================
--- trunk/gcalctool/lr_parser.y (original)
+++ trunk/gcalctool/lr_parser.y Sat Jun 14 06:48:24 2008
@@ -121,12 +121,12 @@
}
| value '=' tSTO '(' tINUMBER ')' {
int val;
- mpcmi($5, &val);
+ val = mp_cast_to_int($5);
do_sto_reg(val, $1);
}
| value tSTO '(' tINUMBER ')' {
int val;
- mpcmi($4, &val);
+ val = mp_cast_to_int($4);
do_sto_reg(val, $1);
}
| tCLR {
@@ -190,8 +190,7 @@
rcl:
tRCL '(' tINUMBER ')' {
- int val;
- mpcmi($3, &val);
+ int val = mp_cast_to_int($3);
do_rcl_reg(val, $$);
}
;
Modified: trunk/gcalctool/mp.c
==============================================================================
--- trunk/gcalctool/mp.c (original)
+++ trunk/gcalctool/mp.c Sat Jun 14 06:48:24 2008
@@ -78,7 +78,7 @@
static int mpcmpi(int *, int *);
static int mpcmpr(int *, float *);
-static int mpcomp(int *, int *);
+static int mpcomp(const int *, const int *);
static int pow_ii(int *, int *);
static void mpadd2(int *, int *, int *, int *, int *);
@@ -418,7 +418,7 @@
--x;
mpchk(&c__2, &c__6);
- mpcim(iy, &MP.r[MP.t + 4]);
+ mp_set_from_integer(*iy, &MP.r[MP.t + 4]);
mpadd(&x[1], &MP.r[MP.t + 4], &z[1]);
}
@@ -556,7 +556,7 @@
/* HERE ABS(X) .GE. 1. SEE IF X = +-1 */
- mpcim(&x[1], &MP.r[i3 - 1]);
+ mp_set_from_integer(x[1], &MP.r[i3 - 1]);
if (mpcomp(&x[1], &MP.r[i3 - 1]) != 0) goto L10;
/* X = +-1 SO RETURN +-PI/2 */
@@ -581,7 +581,7 @@
L40:
i2 = i3 - (MP.t + 2);
- mpcim(&c__1, &MP.r[i2 - 1]);
+ mp_set_from_integer(1, &MP.r[i2 - 1]);
mpstr(&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]);
@@ -698,7 +698,7 @@
void
-mpcdm(double *dx, int *z)
+mp_set_from_double(double dx, int *z)
{
int i__1;
@@ -720,8 +720,8 @@
/* CHECK SIGN */
- if (*dx < 0.) goto L20;
- else if (*dx == 0) goto L10;
+ if (dx < 0.) goto L20;
+ else if (dx == 0) goto L10;
else goto L30;
/* IF DX = 0D0 RETURN 0 */
@@ -734,14 +734,14 @@
L20:
rs = -1;
- dj = -(*dx);
+ dj = -dx;
goto L40;
/* DX .GT. 0D0 */
L30:
rs = 1;
- dj = *dx;
+ dj = dx;
L40:
ie = 0;
@@ -893,11 +893,11 @@
void
-mpcim(int *ix, int *z)
+mp_set_from_integer(int ix, int *z)
{
int i__1;
- static int i, n;
+ static int i;
/* CONVERTS INTEGER IX TO MULTIPLE-PRECISION Z.
* CHECK LEGALITY OF B, T, M AND MXR
@@ -906,9 +906,8 @@
--z; /* Parameter adjustments */
mpchk(&c__1, &c__4);
- n = *ix;
- if (n < 0) goto L20;
- else if (n == 0) goto L10;
+ if (ix < 0) goto L20;
+ else if (ix == 0) goto L10;
else goto L30;
L10:
@@ -916,7 +915,7 @@
return;
L20:
- n = -n;
+ ix = -ix;
z[1] = -1;
goto L40;
@@ -933,9 +932,9 @@
i__1 = MP.t;
for (i = 2; i <= i__1; ++i) z[i + 1] = 0;
-/* INSERT N */
+/* INSERT IX */
- z[MP.t + 2] = n;
+ z[MP.t + 2] = ix;
/* NORMALIZE BY CALLING MPMUL2 */
@@ -943,16 +942,17 @@
}
-void
-mpcmd(int *x, double *dz)
+double
+mp_cast_to_double(const int *x)
{
int i__1;
- double d__1;
+ double d__1, ret_val = 0.0;
static int i, tm;
static double db, dz2;
-/* CONVERTS MULTIPLE-PRECISION X TO DOUBLE-PRECISION DZ.
+/* CONVERTS MULTIPLE-PRECISION X TO DOUBLE-PRECISION,
+ * AND RETURNS RESULT.
* ASSUMES X IS IN ALLOWABLE RANGE FOR DOUBLE-PRECISION
* NUMBERS. THERE IS SOME LOSS OF ACCURACY IF THE
* EXPONENT IS LARGE.
@@ -962,46 +962,45 @@
--x; /* Parameter adjustments */
mpchk(&c__1, &c__4);
- *dz = 0.;
- if (x[1] == 0) return;
+ if (x[1] == 0) return 0.0;
/* DB = DFLOAT(B) IS NOT ANSI STANDARD, SO USE FLOAT AND DBLE */
db = (double) ((float) MP.b);
i__1 = MP.t;
for (i = 1; i <= i__1; ++i) {
- *dz = db * *dz + (double) ((float) x[i + 2]);
+ ret_val = db * ret_val + (double) ((float) x[i + 2]);
tm = i;
/* CHECK IF FULL DOUBLE-PRECISION ACCURACY ATTAINED */
- dz2 = *dz + 1.;
+ dz2 = ret_val + 1.;
/* TEST BELOW NOT ALWAYS EQUIVALENT TO - IF (DZ2.LE.DZ) GO TO 20,
* FOR EXAMPLE ON CYBER 76.
*/
- if (dz2 - *dz <= 0.) goto L20;
+ if (dz2 - ret_val <= 0.) goto L20;
}
/* NOW ALLOW FOR EXPONENT */
L20:
i__1 = x[2] - tm;
- *dz *= mppow_di(&db, &i__1);
+ ret_val *= mppow_di(&db, &i__1);
/* CHECK REASONABLENESS OF RESULT. */
- if (*dz <= 0.) goto L30;
+ if (ret_val <= 0.) goto L30;
/* LHS SHOULD BE .LE. 0.5 BUT ALLOW FOR SOME ERROR IN DLOG */
- if ((d__1 = (double) ((float) x[2]) - (log(*dz) / log((double)
+ if ((d__1 = (double) ((float) x[2]) - (log(ret_val) / log((double)
((float) MP.b)) + .5), C_abs(d__1)) > .6) {
goto L30;
}
- if (x[1] < 0) *dz = -(*dz);
- return;
+ if (x[1] < 0) ret_val = -ret_val;
+ return ret_val;
/* FOLLOWING MESSAGE INDICATES THAT X IS TOO LARGE OR SMALL -
* TRY USING MPCMDE INSTEAD.
@@ -1009,10 +1008,13 @@
L30:
if (v->MPerrors) {
- FPRINTF(stderr, "*** FLOATING-POINT OVER/UNDER-FLOW IN MPCMD ***\n");
+ FPRINTF(stderr, "*** FLOATING-POINT OVER/UNDER-FLOW IN "
+ "MP_CAST_TO_DOUBLE ***\n");
}
mperr();
+
+ return 0.0;
}
@@ -1078,48 +1080,47 @@
}
-void
-mpcmi(int *x, int *iz)
+int
+mp_cast_to_int(const int *x)
{
- int i__1;
-
+ int i__1, ret_val = 0;
static int i, j, k, j1, x2, kx, xs, izs;
-/* CONVERTS MULTIPLE-PRECISION X TO INTEGER IZ,
+/* CONVERTS MULTIPLE-PRECISION X TO INTEGER, AND
+ * RETURNS RESULT.
* ASSUMING THAT X NOT TOO LARGE (ELSE USE MPCMIM).
* X IS TRUNCATED TOWARDS ZERO.
* IF INT(X)IS TOO LARGE TO BE REPRESENTED AS A SINGLE-
* PRECISION INTEGER, IZ IS RETURNED AS ZERO. THE USER
* MAY CHECK FOR THIS POSSIBILITY BY TESTING IF
* ((X(1).NE.0).AND.(X(2).GT.0).AND.(IZ.EQ.0)) IS TRUE ON
- * RETURN FROM MPCMI.
+ * RETURN FROM MP_CAST_TO_INST.
*/
--x; /* Parameter adjustments */
xs = x[1];
- *iz = 0;
- if (xs == 0) return;
+ if (xs == 0) return 0;
- if (x[2] <= 0) return;
+ if (x[2] <= 0) return 0;
x2 = x[2];
i__1 = x2;
for (i = 1; i <= i__1; ++i) {
- izs = *iz;
- *iz = MP.b * *iz;
- if (i <= MP.t) *iz += x[i + 2];
+ izs = ret_val;
+ ret_val = MP.b * ret_val;
+ if (i <= MP.t) ret_val += x[i + 2];
/* CHECK FOR SIGNS OF INTEGER OVERFLOW */
- if (*iz <= 0 || *iz <= izs) goto L30;
+ if (ret_val <= 0 || ret_val <= izs) goto L30;
}
/* CHECK THAT RESULT IS CORRECT (AN UNDETECTED OVERFLOW MAY
* HAVE OCCURRED).
*/
- j = *iz;
+ j = ret_val;
i__1 = x2;
for (i = 1; i <= i__1; ++i) {
j1 = j / MP.b;
@@ -1133,15 +1134,15 @@
/* RESULT CORRECT SO RESTORE SIGN AND RETURN */
- *iz = xs * *iz;
- return;
+ ret_val = xs * ret_val;
+ return ret_val;
/* HERE OVERFLOW OCCURRED (OR X WAS UNNORMALIZED), SO
* RETURN ZERO.
*/
L30:
- *iz = 0;
+ return 0;
}
@@ -1244,7 +1245,7 @@
/* CONVERT I TO MULTIPLE-PRECISION AND COMPARE */
- mpcim(i, &MP.r[MP.t + 4]);
+ mp_set_from_integer(*i, &MP.r[MP.t + 4]);
ret_val = mpcomp(&x[1], &MP.r[MP.t + 4]);
return(ret_val);
}
@@ -1342,7 +1343,7 @@
static int
-mpcomp(int *x, int *y)
+mpcomp(const int *x, const int *y)
{
int ret_val, i__1, i__2;
@@ -1429,7 +1430,7 @@
/* COS(0) = 1 */
- mpcim(&c__1, &y[1]);
+ mp_set_from_integer(1, &y[1]);
return;
/* CHECK LEGALITY OF B, T, M AND MXR */
@@ -1478,7 +1479,7 @@
/* COSH(0) = 1 */
- mpcim(&c__1, &y[1]);
+ mp_set_from_integer(1, &y[1]);
return;
/* CHECK LEGALITY OF B, T, M AND MXR */
@@ -1536,7 +1537,7 @@
j1 = -j1;
L40:
- mpcim(&i1, &q[1]);
+ mp_set_from_integer(i1, &q[1]);
if (j1 != 1) mpdivi(&q[1], &j1, &q[1]);
}
@@ -1955,18 +1956,10 @@
int
-mpeq(int *x, int *y)
+mp_is_equal(const int *x, const int *y)
{
- int ret_val;
-
-/* RETURNS LOGICAL VALUE OF (X .EQ. Y) FOR MP X AND Y. */
-
- --y; /* Parameter adjustments */
- --x;
-
- ret_val = mpcomp(&x[1], &y[1]) == 0;
-
- return(ret_val);
+/* RETURNS LOGICAL VALUE OF (X == Y) FOR MP X AND Y. */
+ return (mpcomp(x, y) == 0);
}
@@ -2009,7 +2002,7 @@
/* CHECK FOR X = 0 */
if (x[1] != 0) goto L10;
- mpcim(&c__1, &y[1]);
+ mp_set_from_integer(1, &y[1]);
return;
/* CHECK IF ABS(X) .LT. 1 */
@@ -2072,7 +2065,7 @@
/* GET FRACTIONAL AND INTEGER PARTS OF ABS(X) */
- mpcmi(&MP.r[i3 - 1], &ix);
+ ix = mp_cast_to_int(&MP.r[i3 - 1]);
mpcmf(&MP.r[i3 - 1], &MP.r[i3 - 1]);
/* ATTACH SIGN TO FRACTIONAL PART AND COMPUTE EXP OF IT */
@@ -2092,7 +2085,7 @@
i2 = MP.t + 5;
i3 = i2 + MP.t + 2;
MP.r[i3 - 1] = 0;
- mpcim(&xs, &MP.r[i2 - 1]);
+ mp_set_from_integer(xs, &MP.r[i2 - 1]);
i = 1;
/* LOOP FOR E COMPUTATION. DECREASE T IF POSSIBLE. */
@@ -2356,50 +2349,26 @@
int
-mpge(int *x, int *y)
+mp_is_greater_equal(const int *x, const int *y)
{
- int ret_val;
-
-/* RETURNS LOGICAL VALUE OF (X .GE. Y) FOR MP X AND Y. */
-
- --y; /* Parameter adjustments */
- --x;
-
- ret_val = mpcomp(&x[1], &y[1]) >= 0;
-
- return(ret_val);
+/* RETURNS LOGICAL VALUE OF (X >= Y) FOR MP X AND Y. */
+ return (mpcomp(x, y) >= 0);
}
int
-mpgt(int *x, int *y)
+mp_is_greater_than(const int *x, const int *y)
{
- int ret_val;
-
-/* RETURNS LOGICAL VALUE OF (X .GT. Y) FOR MP X AND Y. */
-
- --y; /* Parameter adjustments */
- --x;
-
- ret_val = mpcomp(&x[1], &y[1]) > 0;
-
- return(ret_val);
+/* RETURNS LOGICAL VALUE OF (X > Y) FOR MP X AND Y. */
+ return (mpcomp(x, y) > 0);
}
int
-mple(int *x, int *y)
+mp_is_less_equal(const int *x, const int *y)
{
- int ret_val;
-
-/* RETURNS LOGICAL VALUE OF (X .LE. Y) FOR MP X AND Y. */
-
- --y; /* Parameter adjustments */
- --x;
-
- ret_val = mpcomp(&x[1], &y[1]) <= 0;
-
- return(ret_val);
+/* RETURNS LOGICAL VALUE OF (X <= Y) FOR MP X AND Y. */
+ return (mpcomp(x, y) <= 0);
}
@@ -2609,18 +2578,10 @@
int
-mplt(int *x, int *y)
+mp_is_less_than(const int *x, const int *y)
{
- int ret_val;
-
-/* RETURNS LOGICAL VALUE OF (X .LT. Y) FOR MP X AND Y. */
-
- --y; /* Parameter adjustments */
- --x;
-
- ret_val = mpcomp(&x[1], &y[1]) < 0;
-
- return(ret_val);
+/* RETURNS LOGICAL VALUE OF (X < Y) FOR MP X AND Y. */
+ return (mpcomp(x, y) < 0);
}
@@ -3283,7 +3244,7 @@
/* N = 0, RETURN Y = 1. */
L10:
- mpcim(&c__1, &y[1]);
+ mp_set_from_integer(1, &y[1]);
return;
/* N .LT. 0 */
@@ -3324,7 +3285,7 @@
/* SET PRODUCT TERM TO ONE */
- mpcim(&c__1, &y[1]);
+ mp_set_from_integer(1, &y[1]);
/* MAIN LOOP, LOOK AT BITS OF N2 FROM RIGHT */
@@ -3998,7 +3959,7 @@
L10:
y[1] = 0;
- if (*is == 0) mpcim(&c__1, &y[1]);
+ if (*is == 0) mp_set_from_integer(1, &y[1]);
return;
L20:
@@ -4016,7 +3977,7 @@
goto L10;
L40:
- if (*is == 0) mpcim(&c__1, &MP.r[i2 - 1]);
+ if (*is == 0) mp_set_from_integer(1, &MP.r[i2 - 1]);
if (*is != 0) mpstr(&x[1], &MP.r[i2 - 1]);
y[1] = 0;
@@ -4272,7 +4233,7 @@
/* HERE ABS(X) IS VERY LARGE */
- mpcim(&xs, &y[1]);
+ mp_set_from_integer(xs, &y[1]);
return;
/* HERE ABS(X) NOT SO LARGE */
Modified: trunk/gcalctool/mp.h
==============================================================================
--- trunk/gcalctool/mp.h (original)
+++ trunk/gcalctool/mp.h Sat Jun 14 06:48:24 2008
@@ -25,21 +25,24 @@
#define MP_SIZE 1000 /* Size of the multiple precision values. */
void mperr();
-int mpeq(int *, int *);
-int mpge(int *, int *);
-int mpgt(int *, int *);
-int mple(int *, int *);
-int mplt(int *, int *);
+
+int mp_is_equal(const int *, const int *);
+int mp_is_greater_equal(const int *, const int *);
+int mp_is_greater_than(const int *, const int *);
+int mp_is_less_equal(const int *, const int *);
+int mp_is_less_than(const int *, const int *);
+
+double mp_cast_to_double(const int *);
+int mp_cast_to_int(const int *);
+void mp_set_from_double(double, int *);
+void mp_set_from_integer(int, int *);
+
void mpabs(int *, int *);
void mpadd(int *, int *, int *);
void mpaddi(int *, int *, int *);
void mpasin(int *, int *);
void mpatan(int *, int *);
-void mpcdm(double *, int *);
-void mpcim(int *, int *);
-void mpcmd(int *, double *);
void mpcmf(int *, int *);
-void mpcmi(int *, int *);
void mpcmim(int *, int *);
void mpcos(int *, int *);
void mpcosh(int *, int *);
Modified: trunk/gcalctool/mpmath.c
==============================================================================
--- trunk/gcalctool/mpmath.c (original)
+++ trunk/gcalctool/mpmath.c Sat Jun 14 06:48:24 2008
@@ -62,10 +62,10 @@
{
double dres, dval;
- mpcmd(s1, &dres);
- mpcmd(s2, &dval);
+ dres = mp_cast_to_double(s1);
+ dval = mp_cast_to_double(s2);
dres = setbool(ibool(dres) & ibool(dval));
- mpcdm(&dres, t);
+ mp_set_from_double(dres, t);
}
@@ -74,10 +74,10 @@
{
double dres, dval;
- mpcmd(s1, &dres);
- mpcmd(s2, &dval);
+ dres = mp_cast_to_double(s1);
+ dval = mp_cast_to_double(s2);
dres = setbool(ibool(dres) | ibool(dval));
- mpcdm(&dres, t);
+ mp_set_from_double(dres, t);
}
@@ -86,10 +86,10 @@
{
double dres, dval;
- mpcmd(s1, &dres);
- mpcmd(s2, &dval);
+ dres = mp_cast_to_double(s1);
+ dval = mp_cast_to_double(s2);
dres = setbool(ibool(dres) ^ ibool(dval));
- mpcdm(&dres, t);
+ mp_set_from_double(dres, t);
}
@@ -98,52 +98,45 @@
{
double dres, dval;
- mpcmd(s1, &dres);
- mpcmd(s2, &dval);
+ dres = mp_cast_to_double(s1);
+ dval = mp_cast_to_double(s2);
dres = setbool(~ibool(dres) ^ ibool(dval));
- mpcdm(&dres, t);
+ mp_set_from_double(dres, t);
}
void
calc_not(int s1[MP_SIZE], int t[MP_SIZE])
{
- double dval;
-
- mpcmd(s1, &dval);
+ double dval = mp_cast_to_double(s1);
+
dval = setbool(~ibool(dval));
- mpcdm(&dval, t);
+ mp_set_from_double(dval, t);
}
void
calc_rand(int t[MP_SIZE])
{
- double dval = drand48();
-
- mpcdm(&dval, t);
+ mp_set_from_double(drand48(), t);
}
void
calc_u32(int s1[MP_SIZE], int t1[MP_SIZE])
{
- double dval;
-
- mpcmd(s1, &dval);
+ double dval = mp_cast_to_double(s1);
dval = setbool(ibool(dval));
- mpcdm(&dval, t1);
+ mp_set_from_double(dval, t1);
}
void
calc_u16(int s1[MP_SIZE], int t1[MP_SIZE])
{
- double dval;
-
- mpcmd(s1, &dval);
+ double dval = mp_cast_to_double(s1);
dval = setbool(ibool(dval) & 0xffff);
- mpcdm(&dval, t1);
+ mp_set_from_double(dval, t1);
}
@@ -152,9 +145,8 @@
{
int MP1[MP_SIZE];
int MP2[MP_SIZE];
- int i = 1;
- mpcim(&i, MP1);
+ mp_set_from_integer(1, MP1);
mpstr(s1, MP2);
mpdiv(MP1, MP2, t1);
}
@@ -164,9 +156,7 @@
calc_tenpowx(int s1[MP_SIZE], int t1[MP_SIZE]) /* Calculate 10^x */
{
int MP1[MP_SIZE];
- int i = 10;
-
- mpcim(&i, MP1);
+ mp_set_from_integer(10, MP1);
mppwr2(MP1, s1, t1);
}
@@ -174,25 +164,22 @@
void
calc_xpowy(int MPx[MP_SIZE], int MPy[MP_SIZE], int MPres[MP_SIZE]) /* Do x^y */
{
- int MP0[MP_SIZE], val;
+ int MP0[MP_SIZE];
- do_zero(MP0);
+ mp_set_from_integer(0, MP0);
/* Check if both x and y are zero. If yes, then just return 1.
* See gcalctool bug #451286.
*/
- if (mpeq(MPx, MP0) && mpeq(MPy, MP0)) {
- val = 1;
- mpcim(&val, MPres);
+ if (mp_is_equal(MPx, MP0) && mp_is_equal(MPy, MP0)) {
+ mp_set_from_integer(1, MPres);
- } else if (mplt(MPx, MP0)) { /* Is x < 0 ? */
+ } else if (mp_is_less_than(MPx, MP0)) { /* Is x < 0 ? */
int MPtmp[MP_SIZE];
mpcmim(MPy, MPtmp);
- if (mpeq(MPtmp, MPy)) { /* Is y == int(y) ? */
- int y;
-
- mpcmi(MPy, &y);
+ if (mp_is_equal(MPtmp, MPy)) { /* Is y == int(y) ? */
+ int y = mp_cast_to_int(MPy);
mppwr(MPx, &y, MPres);
} else { /* y != int(y). Force mppwr2 to generate an error. */
mppwr2(MPx, MPy, MPres);
@@ -228,8 +215,10 @@
mpmul(MP1, op2, MP2);
mpsub(op1, MP2, result);
- do_zero(MP1);
- if ((mplt(op2, MP1) && mpgt(result, MP1)) || mplt(result, MP1)) {
+ mp_set_from_integer(0, MP1);
+ if ((mp_is_less_than(op2, MP1)
+ && mp_is_greater_than(result, MP1)) ||
+ mp_is_less_than(result, MP1)) {
mpadd(result, op2, result);
}
@@ -246,20 +235,9 @@
}
void
-do_zero(int t1[MP_SIZE])
-{
- int i = 0;
-
- mpcim(&i, t1);
-}
-
-
-void
do_e(int t1[MP_SIZE])
{
- double e = 2.71828182846;
-
- mpcdm(&e, t1);
+ mp_set_from_double(2.71828182846, t1);
}
@@ -272,7 +250,7 @@
mpsin(s1, MPsin);
mpcos(s1, MPcos);
- mpcmd(MPcos, &cval);
+ cval = mp_cast_to_double(MPcos);
if (cval == 0.0) {
doerr(_("Error, cannot calculate cosine"));
}
@@ -285,19 +263,17 @@
static void
to_rad(int s1[MP_SIZE], int t1[MP_SIZE])
{
- int i, MP1[MP_SIZE], MP2[MP_SIZE];
+ int MP1[MP_SIZE], MP2[MP_SIZE];
if (v->ttype == DEG) {
mppi(MP1);
mpmul(s1, MP1, MP2);
- i = 180;
- mpcim(&i, MP1);
+ mp_set_from_integer(180, MP1);
mpdiv(MP2, MP1, t1);
} else if (v->ttype == GRAD) {
mppi(MP1);
mpmul(s1, MP1, MP2);
- i = 200;
- mpcim(&i, MP1);
+ mp_set_from_integer(200, MP1);
mpdiv(MP2, MP1, t1);
} else {
mpstr(s1, t1);
@@ -308,13 +284,12 @@
static void
do_trig_typeconv(enum trig_type ttype, int s1[MP_SIZE], int t1[MP_SIZE])
{
- int i, MP1[MP_SIZE], MP2[MP_SIZE];
+ int MP1[MP_SIZE], MP2[MP_SIZE];
switch (ttype) {
case DEG:
- i = 180;
- mpcim(&i, MP1);
+ mp_set_from_integer(180, MP1);
mpmul(s1, MP1, MP2);
mppi(MP1);
mpdiv(MP2, MP1, t1);
@@ -325,8 +300,7 @@
break;
case GRAD:
- i = 200;
- mpcim(&i, MP1);
+ mp_set_from_integer(200, MP1);
mpmul(s1, MP1, MP2);
mppi(MP1);
mpdiv(MP2, MP1, t1);
@@ -365,21 +339,19 @@
int MPn1[MP_SIZE], MPpi[MP_SIZE], MPy[MP_SIZE], val;
mppi(MPpi);
- do_zero(MP0);
- val = 1;
- mpcim(&val, MP1);
- val = -1;
- mpcim(&val, MPn1);
+ mp_set_from_integer(0, MP0);
+ mp_set_from_integer(1, MP1);
+ mp_set_from_integer(-1, MPn1);
- if (mpgt(MPx, MP1) || mplt(MPx, MPn1)) {
+ if (mp_is_greater_than(MPx, MP1) || mp_is_less_than(MPx, MPn1)) {
doerr(_("Error"));
mpstr(MP0, MPretval);
- } else if (mpeq(MPx, MP0)) {
+ } else if (mp_is_equal(MPx, MP0)) {
val = 2;
mpdivi(MPpi, &val, MPretval);
- } else if (mpeq(MPx, MP1)) {
+ } else if (mp_is_equal(MPx, MP1)) {
mpstr(MP0, MPretval);
- } else if (mpeq(MPx, MPn1)) {
+ } else if (mp_is_equal(MPx, MPn1)) {
mpstr(MPpi, MPretval);
} else {
mpmul(MPx, MPx, MP2);
@@ -387,7 +359,7 @@
mpsqrt(MP2, MP2);
mpdiv(MP2, MPx, MP2);
mpatan(MP2, MPy);
- if (mpgt(MPx, MP0)) {
+ if (mp_is_greater_than(MPx, MP0)) {
mpstr(MPy, MPretval);
} else {
mpadd(MPy, MPpi, MPretval);
@@ -406,16 +378,15 @@
static void
mpacosh(int *MPx, int *MPretval)
{
- int MP1[MP_SIZE], val;
+ int MP1[MP_SIZE];
- val = 1;
- mpcim(&val, MP1);
- if (mplt(MPx, MP1)) {
+ mp_set_from_integer(1, MP1);
+ if (mp_is_less_than(MPx, MP1)) {
doerr(_("Error"));
- do_zero(MPretval);
+ mp_set_from_integer(0, MPretval);
} else {
+ int val = -1;
mpmul(MPx, MPx, MP1);
- val = -1;
mpaddi(MP1, &val, MP1);
mpsqrt(MP1, MP1);
mpadd(MPx, MP1, MP1);
@@ -455,15 +426,12 @@
{
int MP0[MP_SIZE], MP1[MP_SIZE], MP2[MP_SIZE];
int MP3[MP_SIZE], MPn1[MP_SIZE];
- int val;
- do_zero(MP0);
- val = 1;
- mpcim(&val, MP1);
- val = -1;
- mpcim(&val, MPn1);
+ mp_set_from_integer(0, MP0);
+ mp_set_from_integer(1, MP1);
+ mp_set_from_integer(-1, MPn1);
- if (mpge(MPx, MP1) || mple(MPx, MPn1)) {
+ if (mp_is_greater_equal(MPx, MP1) || mp_is_less_equal(MPx, MPn1)) {
doerr(_("Error"));
mpstr(MP0, MPretval);
} else {
@@ -487,7 +455,7 @@
{
int MP1[MP_SIZE], MP2[MP_SIZE];
- mpcim(&n, MP1);
+ mp_set_from_integer(n, MP1);
mpln(MP1, MP1);
mpln(MPx, MP2);
mpdiv(MP2, MP1, MPretval);
@@ -540,8 +508,8 @@
int val;
int MPbv[MP_SIZE], MP1[MP_SIZE], MP2[MP_SIZE];
- do_zero(MPbv);
- mpcmi(v->MPmvals[3], &len);
+ mp_set_from_integer(0, MPbv);
+ len = mp_cast_to_int(v->MPmvals[3]);
for (i = 0; i < len; i++) {
mpsub(v->MPmvals[0], MPbv, MP1);
val = 2;
@@ -648,8 +616,7 @@
int MP1[MP_SIZE], MP2[MP_SIZE], MP3[MP_SIZE], MP4[MP_SIZE];
mpdiv(v->MPmvals[0], v->MPmvals[1], MP1);
- val = 1;
- mpcim(&val, MP2);
+ mp_set_from_integer(1, MP2);
mpdiv(MP2, v->MPmvals[2], MP3);
mppwr2(MP1, MP3, MP4);
val = -1;
@@ -696,8 +663,7 @@
mpaddi(MP2, &val, MP3);
mpaddi(v->MPmvals[2], &val, MP2);
mpmul(v->MPmvals[2], MP2, MP4);
- val = 2;
- mpcim(&val, MP2);
+ mp_set_from_integer(2, MP2);
mpdiv(MP4, MP2, MP1);
mpdiv(MP3, MP1, MP2);
mpsub(v->MPmvals[0], v->MPmvals[1], MP1);
@@ -739,9 +705,8 @@
* boolean means BINARY representation
*/
- double dval;
BOOLEAN temp;
- mpcmd(s, &dval);
+ double dval = mp_cast_to_double(s);
temp = ibool(dval);
/* There is a reason to do shift like this. Reason is that
@@ -762,26 +727,25 @@
}
dval = setbool(temp);
- mpcdm(&dval, t);
+ mp_set_from_double(dval, t);
}
int
is_integer(int MPnum[MP_SIZE])
{
- int i = 10000;
int MPtt[MP_SIZE], MP0[MP_SIZE], MP1[MP_SIZE];
/* Multiplication and division by 10000 is used to get around a
* limitation to the "fix" for Sun bugtraq bug #4006391 in the
* mpcmim() routine in mp.c, when the exponent is less than 1.
*/
- mpcim(&i, MPtt);
+ mp_set_from_integer(10000, MPtt);
mpmul(MPnum, MPtt, MP0);
mpdiv(MP0, MPtt, MP0);
mpcmim(MP0, MP1);
- return mpeq(MP0, MP1);
+ return mp_is_equal(MP0, MP1);
}
@@ -793,7 +757,7 @@
return 0;
}
mpabs(MPnum, MP1);
- return mpeq(MPnum, MP1);
+ return mp_is_equal(MPnum, MP1);
}
void
@@ -880,16 +844,16 @@
int MP1base[MP_SIZE], MP1[MP_SIZE], MP2[MP_SIZE], MPval[MP_SIZE];
int ndig; /* Total number of digits to generate. */
int ddig; /* Number of digits to left of decimal sep. */
- int dval, n, i;
+ int dval, i;
optr = target;
mpabs(MPnumber, MPval);
- do_zero(MP1);
- if (mplt(MPnumber, MP1)) {
+ mp_set_from_integer(0, MP1);
+ if (mp_is_less_than(MPnumber, MP1)) {
*optr++ = '-';
}
- mpcim(&basevals[base], MP1base);
+ mp_set_from_integer(basevals[base], MP1base);
mppwr(MP1base, &v->accuracy, MP1);
/* FIXME: string const. if MPstr_to_num can get it */
@@ -898,14 +862,13 @@
mpdiv(MP2, MP1, MP1);
mpadd(MPval, MP1, MPval);
- n = 1;
- mpcim(&n, MP2);
- if (mplt(MPval, MP2)) {
+ mp_set_from_integer(1, MP2);
+ if (mp_is_less_than(MPval, MP2)) {
ddig = 0;
*optr++ = '0';
cmax--;
} else {
- for (ddig = 0; mpge(MPval, MP2); ddig++) {
+ for (ddig = 0; mp_is_greater_equal(MPval, MP2); ddig++) {
mpdiv(MPval, MP1base, MPval);
}
}
@@ -918,7 +881,7 @@
*optr++ = v->radix[i];
}
mpmul(MPval, MP1base, MPval);
- mpcmi(MPval, &dval);
+ dval = mp_cast_to_int(MPval);
if (dval > basevals[base]-1) {
dval = basevals[base]-1;
@@ -967,44 +930,42 @@
}
optr = target;
mpabs(MPnumber, MPval);
- do_zero(MP1);
- if (mplt(MPnumber, MP1)) {
+ mp_set_from_integer(0, MP1);
+ if (mp_is_less_than(MPnumber, MP1)) {
*optr++ = '-';
}
mpstr(MPval, MPmant);
- mpcim(&basevals[base], MP1base);
+ mp_set_from_integer(basevals[base], MP1base);
n = 3;
mppwr(MP1base, &n, MP3base);
n = 10;
mppwr(MP1base, &n, MP10base);
- n = 1;
- mpcim(&n, MP1);
+ mp_set_from_integer(1, MP1);
mpdiv(MP1, MP10base, MPatmp);
- do_zero(MP1);
- if (!mpeq(MPmant, MP1)) {
- while (!eng && mpge(MPmant, MP10base)) {
+ mp_set_from_integer(0, MP1);
+ if (!mp_is_equal(MPmant, MP1)) {
+ while (!eng && mp_is_greater_equal(MPmant, MP10base)) {
exp += 10;
mpmul(MPmant, MPatmp, MPmant);
}
- while ((!eng && mpge(MPmant, MP1base)) ||
- (eng && (mpge(MPmant, MP3base) || exp % 3 != 0))) {
+ while ((!eng && mp_is_greater_equal(MPmant, MP1base)) ||
+ (eng && (mp_is_greater_equal(MPmant, MP3base) || exp % 3 != 0))) {
exp += 1;
mpdiv(MPmant, MP1base, MPmant);
}
- while (!eng && mplt(MPmant, MPatmp)) {
+ while (!eng && mp_is_less_than(MPmant, MPatmp)) {
exp -= 10;
mpmul(MPmant, MP10base, MPmant);
}
- n = 1;
- mpcim(&n, MP1);
- while (mplt(MPmant, MP1) || (eng && exp % 3 != 0)) {
+ mp_set_from_integer(1, MP1);
+ while (mp_is_less_than(MPmant, MP1) || (eng && exp % 3 != 0)) {
exp -= 1;
mpmul(MPmant, MP1base, MPmant);
}
@@ -1028,9 +989,8 @@
SNPRINTF(half, MAXLINE, "0.5");
MPstr_to_num(half, DEC, MP1);
mpaddi(MP1, &exp, MPval);
- n = 1;
- mpcim(&n, MP1);
- for (ddig = 0; mpge(MPval, MP1); ddig++) {
+ mp_set_from_integer(1, MP1);
+ for (ddig = 0; mp_is_greater_equal(MPval, MP1); ddig++) {
mpdiv(MPval, MP1base, MPval);
}
@@ -1040,7 +1000,7 @@
while (ddig-- > 0) {
mpmul(MPval, MP1base, MPval);
- mpcmi(MPval, &dval);
+ dval = mp_cast_to_int(MPval);
*optr++ = digits[dval];
dval = -dval;
mpaddi(MPval, &dval, MPval);
@@ -1056,7 +1016,7 @@
void
make_number(char *target, int target_len, int *MPnumber, int base, int ignoreError)
{
- double number, val;
+ double val;
/* NOTE: make_number can currently set v->error when converting to a double.
* This is to provide the same look&feel as V3 even though gcalctool
@@ -1066,7 +1026,8 @@
* order to do these tests.
*/
- mpcmd(MPnumber, &number);
+ double number = mp_cast_to_double(MPnumber);
+
val = fabs(number);
if (v->error && !ignoreError) {
STRNCPY(target, _("Error"), target_len - 1);
@@ -1110,8 +1071,8 @@
int exp_sign = 1;
int negate = 0;
- do_zero(MPval);
- mpcim(&basevals[(int) base], MPbase);
+ mp_set_from_integer(0, MPval);
+ mp_set_from_integer(basevals[(int) base], MPbase);
optr = str;
@@ -1136,7 +1097,7 @@
optr++;
for (i = 1; (inum = char_val(*optr)) >= 0; i++) {
mppwr(MPbase, &i, MP1);
- mpcim(&inum, MP2);
+ mp_set_from_integer(inum, MP2);
mpdiv(MP2, MP1, MP1);
mpadd(MPval, MP1, MPval);
optr++;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]