From bbcc481006d4b5f4e8d1276db2220cf96a355985 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 23 May 2004 20:03:49 +0000 Subject: xc/programs/xcalc/math.c xcalc -rpn mode errors (Geoffery Coram) --- math.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'math.c') diff --git a/math.c b/math.c index b222e4b..913e81f 100644 --- a/math.c +++ b/math.c @@ -1,5 +1,7 @@ -/* $XConsortium: math.c,v 1.17 91/07/25 17:51:34 rws Exp $ +/* $XConsortium: math.c,v 1.17 91/07/25 17:51:34 rws Exp $ + * $MIT: contrib/programs/xcalc/math.c,v 3.2 1999/12/14 18:53:00 gjcoram Exp$ * $XFree86: xc/programs/xcalc/math.c,v 1.5tsi Exp $ + * $XdotOrg: $ * * math.c - mathematics functions for a hand calculator under X * @@ -14,6 +16,8 @@ * original calculator, and it still needs to be rewritten. The HP * functionality should be separated from the TI functionality. * Beware the HP functions: there are still errors here. + * + * Geoffrey Coram fixed most of the HP mode bugs. */ #include @@ -163,8 +167,8 @@ int pre_op(keynum) #ifndef IEEE /* cannot assign result of setjmp under ANSI C, use global instead */ -static int SignalKind; -static int SignalCode; +static volatile int SignalKind; +static volatile int SignalCode; void fail_op() { @@ -323,8 +327,8 @@ numeric(keynum) case kSTO: mem[cell] = dnum; lift_enabled = 1; - entered = 2; - clrdisp++; + entered = 2; + clrdisp++; break; case kRCL: PushNum(dnum); @@ -332,13 +336,13 @@ numeric(keynum) sprintf(dispstr, "%.8g", dnum); lift_enabled = 1; entered = 1; - clrdisp = 0; + clrdisp++; break; case kSUM: mem[cell] += dnum; lift_enabled = 1; - entered = 2; - clrdisp++; + entered = 2; + clrdisp++; break; } memop = kCLR; @@ -376,6 +380,7 @@ numeric(keynum) DrawDisplay(); if (clrdisp && keynum != kZERO) clrdisp=0; /*no leading 0s*/ + memop = keynum; entered=1; lift_enabled = 0; } @@ -388,10 +393,21 @@ bkspf(void) if (! flagINV) { - if (entered!=1 || clrdisp) + if (entered!=1) { + clearf(); + return; + } + if (clrdisp) return; - if ((int) strlen(dispstr) > 0) + if ((int) strlen(dispstr) > 0) { + if (dispstr[strlen(dispstr)-1] == '.') + Dpoint=0; +#ifdef X_LOCALE + if (dispstr[strlen(dispstr)-1] == localeconv()->decimal_point) + Dpoint=0; +#endif dispstr[strlen(dispstr)-1] = 0; + } if (strlen(dispstr) == 0) { strcat(dispstr, "0"); clrdisp++; @@ -412,7 +428,7 @@ decf(void) { flagINV=0; if (clrdisp) { - if (rpn) + if (rpn && lift_enabled) PushNum(dnum); strcpy(dispstr,"0"); } @@ -822,6 +838,7 @@ oneop(int keynum) return; } + memop = keynum; entered=2; clrdisp=1; flagINV=0; -- cgit v1.2.3