--- ray/src/common/calfunc.c 2003/02/22 02:07:21 2.8
+++ ray/src/common/calfunc.c 2006/05/10 15:21:20 2.15
@@ -1,5 +1,5 @@
#ifndef lint
-static const char RCSid[] = "$Id: calfunc.c,v 2.8 2003/02/22 02:07:21 greg Exp $";
+static const char RCSid[] = "$Id: calfunc.c,v 2.15 2006/05/10 15:21:20 greg Exp $";
#endif
/*
* calfunc.c - routines for calcomp using functions.
@@ -10,69 +10,14 @@ static const char RCSid[] = "$Id: calfunc.c,v 2.8 2003
* 2/19/03 Eliminated conditional compiles in favor of esupport extern.
*/
-/* ====================================================================
- * The Radiance Software License, Version 1.0
- *
- * Copyright (c) 1990 - 2002 The Regents of the University of California,
- * through Lawrence Berkeley National Laboratory. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
- * "This product includes Radiance software
- * (http://radsite.lbl.gov/)
- * developed by the Lawrence Berkeley National Laboratory
- * (http://www.lbl.gov/)."
- * Alternately, this acknowledgment may appear in the software itself,
- * if and wherever such third-party acknowledgments normally appear.
- *
- * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
- * and "The Regents of the University of California" must
- * not be used to endorse or promote products derived from this
- * software without prior written permission. For written
- * permission, please contact radiance@radsite.lbl.gov.
- *
- * 5. Products derived from this software may not be called "Radiance",
- * nor may "Radiance" appear in their name, without prior written
- * permission of Lawrence Berkeley National Laboratory.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of Lawrence Berkeley National Laboratory. For more
- * information on Lawrence Berkeley National Laboratory, please see
- * .
- */
+#include "copyright.h"
#include
-
+#include
#include
-
#include
+#include "rterror.h"
#include "calcomp.h"
/* bits in argument flag (better be right!) */
@@ -89,18 +34,18 @@ typedef struct activation {
static ACTIVATION *curact = NULL;
-static double libfunc();
+static double libfunc(char *fname, VARDEF *vp);
#ifndef MAXLIB
#define MAXLIB 64 /* maximum number of library functions */
#endif
-static double l_if(), l_select(), l_rand();
-static double l_floor(), l_ceil();
-static double l_sqrt();
-static double l_sin(), l_cos(), l_tan();
-static double l_asin(), l_acos(), l_atan(), l_atan2();
-static double l_exp(), l_log(), l_log10();
+static double l_if(char *), l_select(char *), l_rand(char *);
+static double l_floor(char *), l_ceil(char *);
+static double l_sqrt(char *);
+static double l_sin(char *), l_cos(char *), l_tan(char *);
+static double l_asin(char *), l_acos(char *), l_atan(char *), l_atan2(char *);
+static double l_exp(char *), l_log(char *), l_log10(char *);
/* functions must be listed alphabetically */
static LIBR library[MAXLIB] = {
@@ -180,7 +125,7 @@ funset(fname, nargs, assign, fptr) /* set a library fu
char *fname;
int nargs;
int assign;
-double (*fptr)();
+double (*fptr)(char *);
{
int oldlibsize = libsize;
char *cp;
@@ -248,7 +193,7 @@ argument(n) /* return nth argument for active functi
register int n;
{
register ACTIVATION *actp = curact;
- register EPNODE *ep;
+ register EPNODE *ep = NULL;
double aval;
if (actp == NULL || --n < 0) {
@@ -310,6 +255,7 @@ badarg:
eputs(actp->name);
eputs(": argument not a function\n");
quit(1);
+ return NULL; /* pro forma return */
}
@@ -398,14 +344,14 @@ VARDEF *vp;
lasterrno = errno;
errno = 0;
d = (*lp->f)(lp->fname);
-#ifdef IEEE
+#ifdef isnan
if (errno == 0)
if (isnan(d))
errno = EDOM;
else if (isinf(d))
errno = ERANGE;
#endif
- if (errno) {
+ if (errno == EDOM || errno == ERANGE) {
wputs(fname);
if (errno == EDOM)
wputs(": domain error\n");
@@ -426,7 +372,7 @@ VARDEF *vp;
static double
-l_if() /* if(cond, then, else) conditional expression */
+l_if(char *nm) /* if(cond, then, else) conditional expression */
/* cond evaluates true if greater than zero */
{
if (argument(1) > 0.0)
@@ -437,11 +383,11 @@ l_if() /* if(cond, then, else) conditional expressio
static double
-l_select() /* return argument #(A1+1) */
+l_select(char *nm) /* return argument #(A1+1) */
{
register int n;
- n = argument(1) + .5;
+ n = (int)(argument(1) + .5);
if (n == 0)
return(nargum()-1);
if (n < 1 || n > nargum()-1) {
@@ -453,7 +399,7 @@ l_select() /* return argument #(A1+1) */
static double
-l_rand() /* random function between 0 and 1 */
+l_rand(char *nm) /* random function between 0 and 1 */
{
double x;
@@ -466,91 +412,91 @@ l_rand() /* random function between 0 and 1 */
static double
-l_floor() /* return largest integer not greater than arg1 */
+l_floor(char *nm) /* return largest integer not greater than arg1 */
{
return(floor(argument(1)));
}
static double
-l_ceil() /* return smallest integer not less than arg1 */
+l_ceil(char *nm) /* return smallest integer not less than arg1 */
{
return(ceil(argument(1)));
}
static double
-l_sqrt()
+l_sqrt(char *nm)
{
return(sqrt(argument(1)));
}
static double
-l_sin()
+l_sin(char *nm)
{
return(sin(argument(1)));
}
static double
-l_cos()
+l_cos(char *nm)
{
return(cos(argument(1)));
}
static double
-l_tan()
+l_tan(char *nm)
{
return(tan(argument(1)));
}
static double
-l_asin()
+l_asin(char *nm)
{
return(asin(argument(1)));
}
static double
-l_acos()
+l_acos(char *nm)
{
return(acos(argument(1)));
}
static double
-l_atan()
+l_atan(char *nm)
{
return(atan(argument(1)));
}
static double
-l_atan2()
+l_atan2(char *nm)
{
return(atan2(argument(1), argument(2)));
}
static double
-l_exp()
+l_exp(char *nm)
{
return(exp(argument(1)));
}
static double
-l_log()
+l_log(char *nm)
{
return(log(argument(1)));
}
static double
-l_log10()
+l_log10(char *nm)
{
return(log10(argument(1)));
}