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.45 by greg, Sat Feb 24 19:11:45 2024 UTC vs.
Revision 2.48 by greg, Sun Feb 25 04:41:44 2024 UTC

# 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 346 | Line 346 | edivi(
346   )
347   {
348      EPNODE  *ep1 = ep->v.kid;
349 <    EPNODE  *ep2 = ep1->sibling;
350 <    double  d;
349 >    double  den = evalue(ep1->sibling);
350  
351 <    d = envalue(ep2);
353 <    if (d == 0.0) {
351 >    if (den == 0.0) {
352          wputs("Division by zero\n");
353          errno = ERANGE;
354          return(0.0);
355      }
356 <    return(envalue(ep1) / d);
356 >    return(envalue(ep1) / den);
357   }
358  
359   static double
# Line 562 | Line 560 | addekid(                       /* add a child to ep */
560      EPNODE      *ek
561   )
562   {
563 <    if (ep->nkids < 0)          /* we don't really handle this properly */
564 <        ep->nkids *= -1;
563 >    if (ep->nkids < 0) {
564 >        eputs("Cannot add kid to EPNODE array\n");
565 >        quit(1);
566 >    }
567      ep->nkids++;
568      if (ep->v.kid == NULL)
569          ep->v.kid = ek;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines