aboutsummaryrefslogtreecommitdiff
path: root/apps/xcalc/math.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/xcalc/math.c')
-rw-r--r--apps/xcalc/math.c125
1 files changed, 20 insertions, 105 deletions
diff --git a/apps/xcalc/math.c b/apps/xcalc/math.c
index 46ddadadb..e1dab3b88 100644
--- a/apps/xcalc/math.c
+++ b/apps/xcalc/math.c
@@ -1,8 +1,4 @@
-/* $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: xc/programs/xcalc/math.c,v 1.3 2004/05/23 20:03:49 alanc Exp $
- *
+/*
* math.c - mathematics functions for a hand calculator under X
*
* Author: John H. Bradley, University of Pennsylvania
@@ -20,17 +16,7 @@
* Geoffrey Coram fixed most of the HP mode bugs.
*/
-#include <stdio.h>
-#include <X11/Xos.h>
-#include <math.h>
-#include <signal.h>
-#if !defined(IEEE) && defined(SVR4)
-#include <siginfo.h>
-#endif
-#include <setjmp.h>
#include "xcalc.h"
-#include <errno.h>
-#include <X11/Xlocale.h>
#ifdef _CRAY /* kludge around Cray STDC compiler */
double (*log_p)() = log;
@@ -72,15 +58,8 @@ double (*pow_p)() = pow;
#define True 1
#define False 0
-extern int rpn;
-extern char dispstr[];
-extern void draw();
-extern void ringbell();
-extern void setflag();
-extern void Quit();
-
#ifndef IEEE
- jmp_buf env;
+jmp_buf env;
#endif
@@ -88,7 +67,7 @@ extern void Quit();
* functions. Much of it is shared between the infix and rpn modes.
*/
-int flagINV, flagPAREN, flagM, drgmode; /* display flags */
+static int flagINV, flagPAREN, flagM, drgmode; /* display flags */
static double drg2rad=PI/180.0; /* Conversion factors for trig funcs */
static double rad2drg=180.0/PI;
@@ -130,10 +109,7 @@ static int priority(int op);
*/
static void
-parse_double (src, fmt, dp)
- char *src;
- char *fmt;
- double *dp;
+parse_double (char *src, char *fmt, double *dp)
{
int olderrno = errno;
@@ -144,8 +120,7 @@ parse_double (src, fmt, dp)
/*********************************/
-int pre_op(keynum)
- int keynum;
+int pre_op(int keynum)
{
if (keynum==-1) return(0);
@@ -168,99 +143,44 @@ int pre_op(keynum)
/* cannot assign result of setjmp under ANSI C, use global instead */
static volatile int SignalKind;
-static volatile int SignalCode;
-void fail_op()
+void fail_op(void)
{
if (SignalKind == SIGFPE)
- switch (SignalCode) {
-#ifdef SVR4
- case FPE_INTDIV: /* integer divide by zero */
- case FPE_FLTDIV: /* floating point divide by zero */
- strcpy(dispstr, "divide by 0");
- break;
- case FPE_INTOVF: /* integer overflow */
- case FPE_FLTOVF: /* floating point overflow */
- strcpy(dispstr, "overflow");
- break;
- case FPE_FLTUND: /* floating point underflow */
- strcpy(dispstr, "underflow");
- break;
- case FPE_FLTRES: /* floating point inexact result */
- strcpy(dispstr, "inexact result");
- break;
- case FPE_FLTINV: /* invalid floating point operation */
- strcpy(dispstr, "invalid op");
- break;
- case FPE_FLTSUB: /* subscript out of range */
- strcpy(dispstr, "out of range");
- break;
-
-#endif /*SVR4*/
-
-#ifdef FPE_FLTDIV_TRAP
- case FPE_FLTDIV_TRAP: strcpy(dispstr,"div by zero"); break;
-#endif
-#ifdef FPE_FLTDIV_FAULT
- case FPE_FLTDIV_FAULT: strcpy(dispstr,"div by zero"); break;
-#endif
-#ifdef FPE_FLTOVF_TRAP
- case FPE_FLTOVF_TRAP: strcpy(dispstr,"overflow"); break;
-#endif
-#ifdef FPE_FLTOVF_FAULT
- case FPE_FLTOVF_FAULT: strcpy(dispstr,"overflow"); break;
-#endif
-#ifdef FPE_FLTUND_TRAP
- case FPE_FLTUND_TRAP: strcpy(dispstr,"underflow"); break;
-#endif
-#ifdef FPE_FLTUND_FAULT
- case FPE_FLTUND_FAULT: strcpy(dispstr,"underflow"); break;
-#endif
- default: strcpy(dispstr,"error");
- }
- else
- if (SignalKind == SIGILL)
- strcpy(dispstr, "illegal operand");
+ strcpy(dispstr, "math error");
+ else if (SignalKind == SIGILL)
+ strcpy(dispstr, "illegal operand");
entered=3;
DrawDisplay();
return;
}
-
-/* keep SVR4 compiler from complaining about scope of arg declaration below */
-typedef struct sigcontext * sigcontextstructp;
/*ARGSUSED*/
-signal_t fperr(sig,code,scp)
- int sig,code;
- sigcontextstructp scp;
+signal_t fperr(int sig)
{
#if defined(SYSV) || defined(SVR4) || defined(linux)
- signal(SIGFPE,(signal_t (*)())fperr);
+ signal(SIGFPE, fperr);
#endif
SignalKind = sig;
- SignalCode = code;
longjmp(env,1);
}
/* for VAX BSD4.3 */
/*ARGSUSED*/
-signal_t illerr(sig,code,scp)
- int sig,code;
- sigcontextstructp scp;
+signal_t illerr(int sig)
{
/* not reset when caught? */
- signal(SIGILL,(signal_t (*)())illerr);
+ signal(SIGILL, illerr);
SignalKind = sig;
- SignalCode = code;
longjmp(env,1);
}
#endif /* not IEEE */
-void post_op()
+void post_op(void)
{
#ifdef DEBUG
showstack("\0");
@@ -302,8 +222,7 @@ DrawDisplay(void)
/*-------------------------------------------------------------------------*/
void
-numeric(keynum)
- int keynum;
+numeric(int keynum)
{
char st[2];
int cell = 0;
@@ -831,7 +750,7 @@ oneop(int keynum)
entered=3;
break;
}
- i=(int) (floor(dnum));
+ dtmp = floor(dnum); i = dtmp;
for (j=1,dnum=1.0; j<=i; j++)
dnum*=(float) j;
break;
@@ -877,8 +796,7 @@ static int numsp;
/*******/
static void
-PushOp(op)
- int op;
+PushOp(int op)
/*******/
{
if (opsp==STACKMAX) {strcpy(dispstr,"stack error"); entered=3;}
@@ -908,8 +826,7 @@ isopempty(void)
#ifdef DEBUG
static void
-showstack(string)
- char *string;
+showstack(char *string)
{
fprintf(stderr, "%s: %lf %lf %lf\n", string, numstack[0], numstack[1],
numstack[2]);
@@ -918,8 +835,7 @@ showstack(string)
/*******/
static void
-PushNum(num)
- double num;
+PushNum(double num)
/*******/
{
if (rpn) {
@@ -990,8 +906,7 @@ ClearStacks(void)
/*******/
static int
-priority(op)
- int op;
+priority(int op)
/*******/
{
switch (op) {