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.3 by greg, Mon May 18 14:15:49 1992 UTC vs.
Revision 2.8 by greg, Sat Feb 22 02:07:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  calfunc.c - routines for calcomp using functions.
6   *
7 < *      The define BIGLIB pulls in a large number of the
11 < *  available math routines.
12 < *
13 < *      If VARIABLE is not defined, only library functions
7 > *      If VARIABLE is not set, only library functions
8   *  can be accessed.
9   *
10 < *     4/2/86
10 > *  2/19/03     Eliminated conditional compiles in favor of esupport extern.
11   */
12  
13 + /* ====================================================================
14 + * The Radiance Software License, Version 1.0
15 + *
16 + * Copyright (c) 1990 - 2002 The Regents of the University of California,
17 + * through Lawrence Berkeley National Laboratory.   All rights reserved.
18 + *
19 + * Redistribution and use in source and binary forms, with or without
20 + * modification, are permitted provided that the following conditions
21 + * are met:
22 + *
23 + * 1. Redistributions of source code must retain the above copyright
24 + *         notice, this list of conditions and the following disclaimer.
25 + *
26 + * 2. Redistributions in binary form must reproduce the above copyright
27 + *       notice, this list of conditions and the following disclaimer in
28 + *       the documentation and/or other materials provided with the
29 + *       distribution.
30 + *
31 + * 3. The end-user documentation included with the redistribution,
32 + *           if any, must include the following acknowledgment:
33 + *             "This product includes Radiance software
34 + *                 (http://radsite.lbl.gov/)
35 + *                 developed by the Lawrence Berkeley National Laboratory
36 + *               (http://www.lbl.gov/)."
37 + *       Alternately, this acknowledgment may appear in the software itself,
38 + *       if and wherever such third-party acknowledgments normally appear.
39 + *
40 + * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
41 + *       and "The Regents of the University of California" must
42 + *       not be used to endorse or promote products derived from this
43 + *       software without prior written permission. For written
44 + *       permission, please contact [email protected].
45 + *
46 + * 5. Products derived from this software may not be called "Radiance",
47 + *       nor may "Radiance" appear in their name, without prior written
48 + *       permission of Lawrence Berkeley National Laboratory.
49 + *
50 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
51 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
52 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
53 + * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
54 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
57 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
58 + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
59 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
60 + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 + * SUCH DAMAGE.
62 + * ====================================================================
63 + *
64 + * This software consists of voluntary contributions made by many
65 + * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
66 + * information on Lawrence Berkeley National Laboratory, please see
67 + * <http://www.lbl.gov/>.
68 + */
69 +
70   #include  <stdio.h>
71  
72   #include  <errno.h>
73  
74 + #include  <math.h>
75 +
76   #include  "calcomp.h"
77  
78                                  /* bits in argument flag (better be right!) */
# Line 38 | Line 91 | static ACTIVATION  *curact = NULL;
91  
92   static double  libfunc();
93  
94 + #ifndef  MAXLIB
95   #define  MAXLIB         64      /* maximum number of library functions */
96 + #endif
97  
98   static double  l_if(), l_select(), l_rand();
99   static double  l_floor(), l_ceil();
45 #ifdef  BIGLIB
100   static double  l_sqrt();
101   static double  l_sin(), l_cos(), l_tan();
102   static double  l_asin(), l_acos(), l_atan(), l_atan2();
103   static double  l_exp(), l_log(), l_log10();
50 #endif
104  
52 #ifdef  BIGLIB
105                          /* functions must be listed alphabetically */
106   static LIBR  library[MAXLIB] = {
107      { "acos", 1, ':', l_acos },
# Line 72 | Line 124 | static LIBR  library[MAXLIB] = {
124  
125   static int  libsize = 16;
126  
75 #else
76                        /* functions must be listed alphabetically */
77 static LIBR  library[MAXLIB] = {
78    { "ceil", 1, ':', l_ceil },
79    { "floor", 1, ':', l_floor },
80    { "if", 3, ':', l_if },
81    { "rand", 1, ':', l_rand },
82    { "select", 1, ':', l_select },
83 };
84
85 static int  libsize = 5;
86
87 #endif
88
89 extern char  *savestr(), *emalloc();
90
91 extern VARDEF  *argf();
92
93 #ifdef  VARIABLE
127   #define  resolve(ep)    ((ep)->type==VAR?(ep)->v.ln:argf((ep)->v.chan))
95 #else
96 #define  resolve(ep)    ((ep)->v.ln)
97 #define varlookup(name) NULL
98 #endif
128  
129  
130   int
131   fundefined(fname)               /* return # of arguments for function */
132   char  *fname;
133   {
134 <    LIBR  *lp;
134 >    register LIBR  *lp;
135      register VARDEF  *vp;
136  
137 <    if ((vp = varlookup(fname)) == NULL || vp->def == NULL
138 <                || vp->def->v.kid->type != FUNC)
110 <        if ((lp = liblookup(fname)) == NULL)
111 <            return(0);
112 <        else
113 <            return(lp->nargs);
114 <    else
137 >    if ((vp = varlookup(fname)) != NULL && vp->def != NULL
138 >                && vp->def->v.kid->type == FUNC)
139          return(nekids(vp->def->v.kid) - 1);
140 +    lp = vp != NULL ? vp->lib : liblookup(fname);
141 +    if (lp == NULL)
142 +        return(0);
143 +    return(lp->nargs);
144   }
145  
146  
# Line 147 | Line 175 | double  *a;
175   }
176  
177  
178 + void
179   funset(fname, nargs, assign, fptr)      /* set a library function */
180   char  *fname;
181   int  nargs;
182   int  assign;
183   double  (*fptr)();
184   {
185 +    int  oldlibsize = libsize;
186 +    char *cp;
187      register LIBR  *lp;
188 <
188 >                                                /* check for context */
189 >    for (cp = fname; *cp; cp++)
190 >        ;
191 >    if (cp == fname)
192 >        return;
193 >    if (cp[-1] == CNTXMARK)
194 >        *--cp = '\0';
195      if ((lp = liblookup(fname)) == NULL) {      /* insert */
196          if (libsize >= MAXLIB) {
197              eputs("Too many library functons!\n");
# Line 185 | Line 222 | double  (*fptr)();
222          lp[0].atyp = assign;
223          lp[0].f = fptr;
224      }
225 <    libupdate(fname);                   /* relink library */
225 >    if (libsize != oldlibsize)
226 >        libupdate(fname);                       /* relink library */
227   }
228  
229  
# Line 237 | Line 275 | register int  n;
275   }
276  
277  
240 #ifdef  VARIABLE
278   VARDEF *
279   argf(n)                         /* return function def for nth argument */
280   int  n;
# Line 282 | Line 319 | int  n;
319   {
320      return(argf(n)->name);
321   }
285 #endif
322  
323  
324   double
# Line 336 | Line 372 | char  *fname;
372   }
373  
374  
339 #ifndef  VARIABLE
340 VARDEF *
341 varinsert(vname)                /* dummy variable insert */
342 char  *vname;
343 {
344    register VARDEF  *vp;
345
346    vp = (VARDEF *)emalloc(sizeof(VARDEF));
347    vp->name = savestr(vname);
348    vp->nlinks = 1;
349    vp->def = NULL;
350    vp->lib = NULL;
351    vp->next = NULL;
352    return(vp);
353 }
354
355
356 varfree(vp)                     /* free dummy variable */
357 register VARDEF  *vp;
358 {
359    freestr(vp->name);
360    efree((char *)vp);
361 }
362 #endif
363
364
365
375   /*
376   *  The following routines are for internal use:
377   */
# Line 446 | Line 455 | l_select()             /* return argument #(A1+1) */
455   static double
456   l_rand()                /* random function between 0 and 1 */
457   {
449    extern double  floor();
458      double  x;
459  
460      x = argument(1);
# Line 460 | Line 468 | l_rand()               /* random function between 0 and 1 */
468   static double
469   l_floor()               /* return largest integer not greater than arg1 */
470   {
463    extern double  floor();
464
471      return(floor(argument(1)));
472   }
473  
# Line 469 | Line 475 | l_floor()              /* return largest integer not greater than
475   static double
476   l_ceil()                /* return smallest integer not less than arg1 */
477   {
472    extern double  ceil();
473
478      return(ceil(argument(1)));
479   }
480  
481  
478 #ifdef  BIGLIB
482   static double
483   l_sqrt()
484   {
482    extern double  sqrt();
483
485      return(sqrt(argument(1)));
486   }
487  
# Line 488 | Line 489 | l_sqrt()
489   static double
490   l_sin()
491   {
491    extern double  sin();
492
492      return(sin(argument(1)));
493   }
494  
# Line 497 | Line 496 | l_sin()
496   static double
497   l_cos()
498   {
500    extern double  cos();
501
499      return(cos(argument(1)));
500   }
501  
# Line 506 | Line 503 | l_cos()
503   static double
504   l_tan()
505   {
509    extern double  tan();
510
506      return(tan(argument(1)));
507   }
508  
# Line 515 | Line 510 | l_tan()
510   static double
511   l_asin()
512   {
518    extern double  asin();
519
513      return(asin(argument(1)));
514   }
515  
# Line 524 | Line 517 | l_asin()
517   static double
518   l_acos()
519   {
527    extern double  acos();
528
520      return(acos(argument(1)));
521   }
522  
# Line 533 | Line 524 | l_acos()
524   static double
525   l_atan()
526   {
536    extern double  atan();
537
527      return(atan(argument(1)));
528   }
529  
# Line 542 | Line 531 | l_atan()
531   static double
532   l_atan2()
533   {
545    extern double  atan2();
546
534      return(atan2(argument(1), argument(2)));
535   }
536  
# Line 551 | Line 538 | l_atan2()
538   static double
539   l_exp()
540   {
554    extern double  exp();
555
541      return(exp(argument(1)));
542   }
543  
# Line 560 | Line 545 | l_exp()
545   static double
546   l_log()
547   {
563    extern double  log();
564
548      return(log(argument(1)));
549   }
550  
# Line 569 | Line 552 | l_log()
552   static double
553   l_log10()
554   {
572    extern double  log10();
573
555      return(log10(argument(1)));
556   }
576 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines