1 |
– |
/* Copyright (c) 1992 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> |
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(); |
47 |
– |
#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(); |
52 |
– |
#endif |
104 |
|
|
54 |
– |
#ifdef BIGLIB |
105 |
|
/* functions must be listed alphabetically */ |
106 |
|
static LIBR library[MAXLIB] = { |
107 |
|
{ "acos", 1, ':', l_acos }, |
124 |
|
|
125 |
|
static int libsize = 16; |
126 |
|
|
77 |
– |
#else |
78 |
– |
/* functions must be listed alphabetically */ |
79 |
– |
static LIBR library[MAXLIB] = { |
80 |
– |
{ "ceil", 1, ':', l_ceil }, |
81 |
– |
{ "floor", 1, ':', l_floor }, |
82 |
– |
{ "if", 3, ':', l_if }, |
83 |
– |
{ "rand", 1, ':', l_rand }, |
84 |
– |
{ "select", 1, ':', l_select }, |
85 |
– |
}; |
86 |
– |
|
87 |
– |
static int libsize = 5; |
88 |
– |
|
89 |
– |
#endif |
90 |
– |
|
91 |
– |
extern char *savestr(), *emalloc(); |
92 |
– |
|
93 |
– |
extern VARDEF *argf(); |
94 |
– |
|
95 |
– |
#ifdef VARIABLE |
127 |
|
#define resolve(ep) ((ep)->type==VAR?(ep)->v.ln:argf((ep)->v.chan)) |
97 |
– |
#else |
98 |
– |
#define resolve(ep) ((ep)->v.ln) |
99 |
– |
#define varlookup(name) NULL |
100 |
– |
#endif |
128 |
|
|
129 |
|
|
130 |
|
int |
175 |
|
} |
176 |
|
|
177 |
|
|
178 |
+ |
void |
179 |
|
funset(fname, nargs, assign, fptr) /* set a library function */ |
180 |
|
char *fname; |
181 |
|
int nargs; |
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"); |
275 |
|
} |
276 |
|
|
277 |
|
|
243 |
– |
#ifdef VARIABLE |
278 |
|
VARDEF * |
279 |
|
argf(n) /* return function def for nth argument */ |
280 |
|
int n; |
319 |
|
{ |
320 |
|
return(argf(n)->name); |
321 |
|
} |
288 |
– |
#endif |
322 |
|
|
323 |
|
|
324 |
|
double |
372 |
|
} |
373 |
|
|
374 |
|
|
342 |
– |
#ifndef VARIABLE |
343 |
– |
static VARDEF *varlist = NULL; /* our list of dummy variables */ |
344 |
– |
|
345 |
– |
|
346 |
– |
VARDEF * |
347 |
– |
varinsert(vname) /* dummy variable insert */ |
348 |
– |
char *vname; |
349 |
– |
{ |
350 |
– |
register VARDEF *vp; |
351 |
– |
|
352 |
– |
vp = (VARDEF *)emalloc(sizeof(VARDEF)); |
353 |
– |
vp->name = savestr(vname); |
354 |
– |
vp->nlinks = 1; |
355 |
– |
vp->def = NULL; |
356 |
– |
vp->lib = liblookup(vname); |
357 |
– |
vp->next = varlist; |
358 |
– |
varlist = vp; |
359 |
– |
return(vp); |
360 |
– |
} |
361 |
– |
|
362 |
– |
|
363 |
– |
varfree(vp) /* free dummy variable */ |
364 |
– |
register VARDEF *vp; |
365 |
– |
{ |
366 |
– |
register VARDEF *vp2; |
367 |
– |
|
368 |
– |
if (vp == varlist) |
369 |
– |
varlist = vp->next; |
370 |
– |
else { |
371 |
– |
for (vp2 = varlist; vp2->next != vp; vp2 = vp2->next) |
372 |
– |
; |
373 |
– |
vp2->next = vp->next; |
374 |
– |
} |
375 |
– |
freestr(vp->name); |
376 |
– |
efree((char *)vp); |
377 |
– |
} |
378 |
– |
|
379 |
– |
|
380 |
– |
libupdate(nm) /* update library */ |
381 |
– |
char *nm; |
382 |
– |
{ |
383 |
– |
register VARDEF *vp; |
384 |
– |
|
385 |
– |
for (vp = varlist; vp != NULL; vp = vp->next) |
386 |
– |
vp->lib = liblookup(vp->name); |
387 |
– |
} |
388 |
– |
#endif |
389 |
– |
|
390 |
– |
|
391 |
– |
|
375 |
|
/* |
376 |
|
* The following routines are for internal use: |
377 |
|
*/ |
479 |
|
} |
480 |
|
|
481 |
|
|
499 |
– |
#ifdef BIGLIB |
482 |
|
static double |
483 |
|
l_sqrt() |
484 |
|
{ |
554 |
|
{ |
555 |
|
return(log10(argument(1))); |
556 |
|
} |
575 |
– |
#endif |