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.47 by greg, Sun Feb 25 04:11:10 2024 UTC vs.
Revision 2.50 by greg, Tue Feb 27 01:24:10 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 208 | Line 208 | epfree(                        /* free a parse tree */
208      }
209      if (frep)
210          efree(epar);
211 +    else
212 +        memset(epar, 0, sizeof(EPNODE));
213   }
214  
215  
# Line 218 | Line 220 | epflatten(                     /* flatten hierarchies for '+', '*' */
220   {
221      EPNODE      *ep;
222  
223 <    if (epar->nkids < 0) {
224 <        eputs("Cannot flatten EPNODE array\n");
225 <        quit(1);
224 <    }
223 >    if (epar->nkids < 0)        /* can't handle array allocations */
224 >        return;
225 >
226      for (ep = epar->v.kid; ep != NULL; ep = ep->sibling)
227 <        while (ep->type == epar->type) {
227 >        while (ep->type == epar->type && ep->nkids > 0) {
228              EPNODE      *ep1 = ep->v.kid;
229              while (ep1->sibling != NULL)
230                  ep1 = ep1->sibling;
231              ep1->sibling = ep->sibling;
232 <            epar->nkids += nekids(ep) - 1;
232 >            epar->nkids += ep->nkids - 1;
233              ep1 = ep->v.kid;
234              *ep = *ep1;
235              efree(ep1);         /* not epfree()! */
# Line 267 | Line 268 | epoptimize(                    /* flatten operations, lists -> arrays *
268  
269                                  /* the following used to be a switch */
270   static double
270 eargument(
271    EPNODE      *ep
272 )
273 {
274    return(argument(ep->v.chan));
275 }
276
277 static double
271   enumber(
272      EPNODE      *ep
273   )
# Line 347 | Line 340 | edivi(
340   )
341   {
342      EPNODE  *ep1 = ep->v.kid;
343 <    EPNODE  *ep2 = ep1->sibling;
351 <    double  d;
343 >    double  den = evalue(ep1->sibling);
344  
345 <    d = evalue(ep2);
354 <    if (d == 0.0) {
345 >    if (den == 0.0) {
346          wputs("Division by zero\n");
347          errno = ERANGE;
348          return(0.0);
349      }
350 <    return(envalue(ep1) / d);
350 >    return(envalue(ep1) / den);
351   }
352  
353   static double
# Line 741 | Line 732 | getE3(void)                    /* E3 -> E4 ^ E3 */
732                          ep2 = ep1;
733                  } else if ((ep3->type == NUM && ep3->v.num == 0) |
734                                  (ep1->type == NUM && ep1->v.num == 1)) {
735 <                        epfree(ep2,1);          /* (E4 ^ 0) or (1 ^ E3) */
745 <                        ep2 = newnode();
735 >                        epfree(ep2,0);          /* (E4 ^ 0) or (1 ^ E3) */
736                          ep2->type = NUM;
737                          ep2->v.num = 1;
738                  } else if (ep3->type == NUM && ep3->v.num == 1) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines