ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/calexpr.c
(Generate patch)

Comparing ray/src/common/calexpr.c (file contents):
Revision 2.46 by greg, Sat Feb 24 19:26:44 2024 UTC vs.
Revision 2.49 by greg, Mon Feb 26 18:16:35 2024 UTC

# Line 37 | Line 37 | static const char      RCSid[] = "$Id$";
37  
38   #define  envalue(ep)    ((ep)->type==NUM ? (ep)->v.num : evalue(ep))
39  
40 < static double  euminus(EPNODE *), eargument(EPNODE *), enumber(EPNODE *);
40 > static double  euminus(EPNODE *), enumber(EPNODE *);
41   static double  echannel(EPNODE *);
42   static double  eadd(EPNODE *), esubtr(EPNODE *),
43                 emult(EPNODE *), edivi(EPNODE *),
# Line 218 | Line 218 | epflatten(                     /* flatten hierarchies for '+', '*' */
218   {
219      EPNODE      *ep;
220  
221 <    if (epar->nkids < 0)        /* we don't really handle this properly */
222 <        epar->nkids *= -1;
221 >    if (epar->nkids < 0)        /* can't handle array allocations */
222 >        return;
223  
224      for (ep = epar->v.kid; ep != NULL; ep = ep->sibling)
225 <        while (ep->type == epar->type) {
225 >        while (ep->type == epar->type && ep->nkids > 0) {
226              EPNODE      *ep1 = ep->v.kid;
227              while (ep1->sibling != NULL)
228                  ep1 = ep1->sibling;
229              ep1->sibling = ep->sibling;
230 <            epar->nkids += nekids(ep) - 1;
230 >            epar->nkids += ep->nkids - 1;
231              ep1 = ep->v.kid;
232              *ep = *ep1;
233              efree(ep1);         /* not epfree()! */
# Line 236 | Line 236 | epflatten(                     /* flatten hierarchies for '+', '*' */
236  
237  
238   void
239 < epoptimize(                     /* flatten operations and lists -> arrays */
239 > epoptimize(                     /* flatten operations, lists -> arrays */
240          EPNODE  *epar
241   )
242   {
243      EPNODE      *ep;
244  
245      if ((epar->type == '+') | (epar->type == '*'))
246 <        epflatten(epar);        /* commutative & associative */
246 >        epflatten(epar);        /* flatten associative operations */
247  
248      if (epar->nkids)            /* do children if any */
249          for (ep = epar->v.kid; ep != NULL; ep = ep->sibling)
# Line 266 | Line 266 | epoptimize(                    /* flatten operations and lists -> array
266  
267                                  /* the following used to be a switch */
268   static double
269 eargument(
270    EPNODE      *ep
271 )
272 {
273    return(argument(ep->v.chan));
274 }
275
276 static double
269   enumber(
270      EPNODE      *ep
271   )
# Line 346 | Line 338 | edivi(
338   )
339   {
340      EPNODE  *ep1 = ep->v.kid;
341 <    EPNODE  *ep2 = ep1->sibling;
350 <    double  d;
341 >    double  den = evalue(ep1->sibling);
342  
343 <    d = evalue(ep2);
353 <    if (d == 0.0) {
343 >    if (den == 0.0) {
344          wputs("Division by zero\n");
345          errno = ERANGE;
346          return(0.0);
347      }
348 <    return(envalue(ep1) / d);
348 >    return(envalue(ep1) / den);
349   }
350  
351   static double
# Line 562 | Line 552 | addekid(                       /* add a child to ep */
552      EPNODE      *ek
553   )
554   {
555 <    if (ep->nkids < 0)          /* we don't really handle this properly */
556 <        ep->nkids *= -1;
555 >    if (ep->nkids < 0) {
556 >        eputs("Cannot add kid to EPNODE array\n");
557 >        quit(1);
558 >    }
559      ep->nkids++;
560      if (ep->v.kid == NULL)
561          ep->v.kid = ek;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines