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.20 by greg, Mon Mar 4 20:34:13 2019 UTC vs.
Revision 2.29 by greg, Sun Feb 25 18:36:27 2024 UTC

# Line 22 | Line 22 | static const char      RCSid[] = "$Id$";
22  
23                                  /* bits in argument flag (better be right!) */
24   #define  AFLAGSIZ       (8*sizeof(unsigned long))
25 < #define  ALISTSIZ       8       /* maximum saved argument list */
25 > #define  ALISTSIZ       10      /* maximum saved argument list */
26  
27   typedef struct activation {
28      char  *name;                /* function name */
# Line 40 | Line 40 | static double  libfunc(char *fname, VARDEF *vp);
40   #define  MAXLIB         64      /* maximum number of library functions */
41   #endif
42  
43 < static double  l_if(char *), l_select(char *), l_rand(char *);
43 > static double  l_if(char *), l_select(char *);
44 > static double  l_min(char *), l_max(char *);
45 > static double  l_rand(char *);
46   static double  l_floor(char *), l_ceil(char *);
47   static double  l_sqrt(char *);
48   static double  l_sin(char *), l_cos(char *), l_tan(char *);
# Line 60 | Line 62 | static LIBR  library[MAXLIB] = {
62      { "if", 3, ':', l_if },
63      { "log", 1, ':', l_log },
64      { "log10", 1, ':', l_log10 },
65 +    { "max", 1, ':', l_max },
66 +    { "min", 1, ':', l_min },
67      { "rand", 1, ':', l_rand },
68      { "select", 1, ':', l_select },
69      { "sin", 1, ':', l_sin },
# Line 67 | Line 71 | static LIBR  library[MAXLIB] = {
71      { "tan", 1, ':', l_tan },
72   };
73  
74 < static int  libsize = 16;
74 > static int  libsize = 18;
75  
76   #define  resolve(ep)    ((ep)->type==VAR?(ep)->v.ln:argf((ep)->v.chan))
77  
78  
79   int
80 < fundefined(                     /* return # of arguments for function */
80 > fundefined(                     /* return # of req'd arguments for function */
81          char  *fname
82   )
83   {
# Line 141 | Line 145 | funset(                                /* set a library function */
145          ;
146      if (cp == fname)
147          return;
148 <    if (cp[-1] == CNTXMARK)
148 >    while (cp[-1] == CNTXMARK) {
149          *--cp = '\0';
150 +        if (cp == fname) return;
151 +    }
152      if ((lp = liblookup(fname)) == NULL) {      /* insert */
153 +        if (fptr == NULL)
154 +                return;                         /* nothing! */
155          if (libsize >= MAXLIB) {
156              eputs("Too many library functons!\n");
157              quit(1);
# Line 347 | Line 355 | libfunc(                               /* execute library function */
355              errno = ERANGE;
356      }
357   #endif
358 <    if (errno == EDOM || errno == ERANGE) {
358 >    if ((errno == EDOM) | (errno == ERANGE)) {
359          wputs(fname);
360          if (errno == EDOM)
361                  wputs(": domain error\n");
# Line 381 | Line 389 | l_if(char *nm)         /* if(cond, then, else) conditional ex
389   static double
390   l_select(char *nm)      /* return argument #(A1+1) */
391   {
392 <        int  n;
392 >        int     narg = nargum();
393 >        double  a1 = argument(1);
394 >        int  n = (int)(a1 + .5);
395  
396 <        n = (int)(argument(1) + .5);
387 <        if (n == 0)
388 <                return(nargum()-1);
389 <        if (n < 1 || n > nargum()-1) {
396 >        if ((a1 < -.5) | (n >= narg)) {
397                  errno = EDOM;
398                  return(0.0);
399          }
400 +        if (!n)         /* asking max index? */
401 +                return(narg-1);
402          return(argument(n+1));
403 + }
404 +
405 +
406 + static double
407 + l_max(char *nm)         /* general maximum function */
408 + {
409 +        int  n = nargum();
410 +        double  vmax = argument(1);
411 +
412 +        while (n > 1) {
413 +                double  v = argument(n--);
414 +                if (vmax < v)
415 +                        vmax = v;
416 +        }
417 +        return(vmax);
418 + }
419 +
420 +
421 + static double
422 + l_min(char *nm)         /* general minimum function */
423 + {
424 +        int  n = nargum();
425 +        double  vmin = argument(1);
426 +
427 +        while (n > 1) {
428 +                double  v = argument(n--);
429 +                if (vmin > v)
430 +                        vmin = v;
431 +        }
432 +        return(vmin);
433   }
434  
435  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines