ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calfunc.c
(Generate patch)

Comparing ray/src/common/calfunc.c (file contents):
Revision 2.23 by greg, Tue Jun 11 22:13:50 2019 UTC vs.
Revision 2.31 by greg, Mon Feb 26 20:55:00 2024 UTC

# Line 15 | Line 15 | static const char      RCSid[] = "$Id$";
15   #include  <stdio.h>
16   #include  <string.h>
17   #include  <errno.h>
18 + #include  <stdlib.h>
19   #include  <math.h>
20  
21   #include  "rterror.h"
# Line 22 | Line 23 | static const char      RCSid[] = "$Id$";
23  
24                                  /* bits in argument flag (better be right!) */
25   #define  AFLAGSIZ       (8*sizeof(unsigned long))
26 < #define  ALISTSIZ       8       /* maximum saved argument list */
26 > #define  ALISTSIZ       10      /* maximum saved argument list */
27  
28   typedef struct activation {
29      char  *name;                /* function name */
# Line 150 | Line 151 | funset(                                /* set a library function */
151          if (cp == fname) return;
152      }
153      if ((lp = liblookup(fname)) == NULL) {      /* insert */
154 +        if (fptr == NULL)
155 +                return;                         /* nothing! */
156          if (libsize >= MAXLIB) {
157              eputs("Too many library functons!\n");
158              quit(1);
# Line 198 | Line 201 | double
201   argument(int n)                 /* return nth argument for active function */
202   {
203      ACTIVATION  *actp = curact;
204 <    EPNODE  *ep = NULL;
204 >    EPNODE  *ep;
205      double  aval;
206  
204    if (!n)                                     /* asking for # arguments? */
205        return((double)nargum());
206
207      if (!actp | (--n < 0)) {
208          eputs("Bad call to argument!\n");
209          quit(1);
# Line 298 | Line 298 | efunc(EPNODE *ep)                      /* evaluate a function */
298   }
299  
300  
301 + double
302 + eargument(                              /* evaluate an argument */
303 +    EPNODE      *ep
304 + )
305 + {
306 +    if ((ep->v.chan <= AFLAGSIZ) & curact->an >> (ep->v.chan-1))
307 +        return(curact->ap[ep->v.chan-1]);
308 +
309 +    return(argument(ep->v.chan));
310 + }
311 +
312 +
313   LIBR *
314   liblookup(char *fname)          /* look up a library function */
315   {
# Line 356 | Line 368 | libfunc(                               /* execute library function */
368              errno = ERANGE;
369      }
370   #endif
371 <    if (errno == EDOM || errno == ERANGE) {
371 >    if ((errno == EDOM) | (errno == ERANGE)) {
372          wputs(fname);
373          if (errno == EDOM)
374                  wputs(": domain error\n");
# Line 394 | Line 406 | l_select(char *nm)     /* return argument #(A1+1) */
406          double  a1 = argument(1);
407          int  n = (int)(a1 + .5);
408  
409 <        if (a1 < -.5 || n >= narg) {
409 >        if ((a1 < -.5) | (n >= narg)) {
410                  errno = EDOM;
411                  return(0.0);
412          }
# Line 408 | Line 420 | static double
420   l_max(char *nm)         /* general maximum function */
421   {
422          int  n = nargum();
423 <        int  i = 1;
412 <        int  vmax = argument(1);
423 >        double  vmax = argument(1);
424  
425 <        while (i++ < n) {
426 <                double  v = argument(i);
425 >        while (n > 1) {
426 >                double  v = argument(n--);
427                  if (vmax < v)
428                          vmax = v;
429          }
# Line 424 | Line 435 | static double
435   l_min(char *nm)         /* general minimum function */
436   {
437          int  n = nargum();
438 <        int  i = 1;
428 <        int  vmin = argument(1);
438 >        double  vmin = argument(1);
439  
440 <        while (i++ < n) {
441 <                double  v = argument(i);
440 >        while (n > 1) {
441 >                double  v = argument(n--);
442                  if (vmin > v)
443                          vmin = v;
444          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines