--- ray/src/common/calfunc.c 1989/02/02 10:34:28 1.1 +++ ray/src/common/calfunc.c 1991/08/02 14:11:17 1.9 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -22,7 +22,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include "calcomp.h" - + /* bits in argument flag (better be right!) */ +#define AFLAGSIZ (8*sizeof(unsigned long)) #define ALISTSIZ 6 /* maximum saved argument list */ typedef struct activation { @@ -35,38 +36,38 @@ typedef struct activation { static ACTIVATION *curact = NULL; -extern double libfunc(); +static double libfunc(); #define MAXLIB 64 /* maximum number of library functions */ -extern double l_if(), l_select(), l_rand(); -extern double l_floor(), l_ceil(); +static double l_if(), l_select(), l_rand(); +static double l_floor(), l_ceil(); #ifdef BIGLIB -extern double l_sqrt(); -extern double l_sin(), l_cos(), l_tan(); -extern double l_asin(), l_acos(), l_atan(), l_atan2(); -extern double l_exp(), l_log(), l_log10(); +static double l_sqrt(); +static double l_sin(), l_cos(), l_tan(); +static double l_asin(), l_acos(), l_atan(), l_atan2(); +static double l_exp(), l_log(), l_log10(); #endif #ifdef BIGLIB /* functions must be listed alphabetically */ static LIBR library[MAXLIB] = { - { "acos", 1, l_acos }, - { "asin", 1, l_asin }, - { "atan", 1, l_atan }, - { "atan2", 2, l_atan2 }, - { "ceil", 1, l_ceil }, - { "cos", 1, l_cos }, - { "exp", 1, l_exp }, - { "floor", 1, l_floor }, - { "if", 3, l_if }, - { "log", 1, l_log }, - { "log10", 1, l_log10 }, - { "rand", 1, l_rand }, - { "select", 1, l_select }, - { "sin", 1, l_sin }, - { "sqrt", 1, l_sqrt }, - { "tan", 1, l_tan }, + { "acos", 1, ':', l_acos }, + { "asin", 1, ':', l_asin }, + { "atan", 1, ':', l_atan }, + { "atan2", 2, ':', l_atan2 }, + { "ceil", 1, ':', l_ceil }, + { "cos", 1, ':', l_cos }, + { "exp", 1, ':', l_exp }, + { "floor", 1, ':', l_floor }, + { "if", 3, ':', l_if }, + { "log", 1, ':', l_log }, + { "log10", 1, ':', l_log10 }, + { "rand", 1, ':', l_rand }, + { "select", 1, ':', l_select }, + { "sin", 1, ':', l_sin }, + { "sqrt", 1, ':', l_sqrt }, + { "tan", 1, ':', l_tan }, }; static int libsize = 16; @@ -74,11 +75,11 @@ static int libsize = 16; #else /* functions must be listed alphabetically */ static LIBR library[MAXLIB] = { - { "ceil", 1, l_ceil }, - { "floor", 1, l_floor }, - { "if", 3, l_if }, - { "rand", 1, l_rand }, - { "select", 1, l_select }, + { "ceil", 1, ':', l_ceil }, + { "floor", 1, ':', l_floor }, + { "if", 3, ':', l_if }, + { "rand", 1, ':', l_rand }, + { "select", 1, ':', l_select }, }; static int libsize = 5; @@ -130,7 +131,10 @@ double *a; act.name = fname; act.prev = curact; act.ap = a; - act.an = (1L<= AFLAGSIZ) + act.an = ~0; + else + act.an = (1L< 0) { lp[0].fname = lp[-1].fname; lp[0].nargs = lp[-1].nargs; + lp[0].atyp = lp[-1].atyp; lp[0].f = lp[-1].f; } else break; libsize++; } - lp[0].fname = fname; /* string must be static! */ + lp[0].fname = fname; /* must be static! */ lp[0].nargs = nargs; + lp[0].atyp = assign; lp[0].f = fptr; } @@ -193,7 +200,7 @@ argument(n) /* return nth argument for active functi register int n; { register ACTIVATION *actp = curact; - EPNODE *ep; + register EPNODE *ep; double aval; if (actp == NULL || --n < 0) { @@ -201,7 +208,7 @@ register int n; quit(1); } /* already computed? */ - if (1L<an) + if (n < AFLAGSIZ && 1L<an) return(actp->ap[n]); if (actp->fun == NULL || (ep = ekid(actp->fun, n+1)) == NULL) { @@ -373,14 +380,22 @@ register VARDEF *vp; } lasterrno = errno; errno = 0; - d = (*vp->lib->f)(); + d = (*vp->lib->f)(vp->lib->fname); #ifdef IEEE - if (!finite(d)) - errno = EDOM; + if (errno == 0) + if (isnan(d)) + errno = EDOM; + else if (isinf(d)) + errno = ERANGE; #endif if (errno) { wputs(fname); - wputs(": bad call\n"); + if (errno == EDOM) + wputs(": domain error\n"); + else if (errno == ERANGE) + wputs(": range error\n"); + else + wputs(": error in call\n"); return(0.0); } errno = lasterrno;