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.21 by greg, Mon Jun 10 13:56:52 2019 UTC

# 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 73 | Line 77 | static int  libsize = 16;
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 (libsize >= MAXLIB) {
154              eputs("Too many library functons!\n");
# Line 195 | Line 201 | argument(int n)                        /* return nth argument for active fu
201      EPNODE  *ep = NULL;
202      double  aval;
203  
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 391 | Line 400 | l_select(char *nm)     /* return argument #(A1+1) */
400                  return(0.0);
401          }
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 +        int  i = 1;
411 +        int  vmax = argument(1);
412 +
413 +        while (i++ < n) {
414 +                double  v = argument(i);
415 +                if (vmax < v)
416 +                        vmax = v;
417 +        }
418 +        return(vmax);
419 + }
420 +
421 +
422 + static double
423 + l_min(char *nm)         /* general minimum function */
424 + {
425 +        int  n = nargum();
426 +        int  i = 1;
427 +        int  vmin = argument(1);
428 +
429 +        while (i++ < n) {
430 +                double  v = argument(i);
431 +                if (vmin > v)
432 +                        vmin = v;
433 +        }
434 +        return(vmin);
435   }
436  
437  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines