/[pspp]/pspp/src/expressions/optimize.c
ViewVC logotype

Diff of /pspp/src/expressions/optimize.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by blp, Tue Mar 1 08:16:16 2005 UTC revision 1.2 by blp, Mon Mar 7 03:04:50 2005 UTC
# Line 102  optimize_tree (union any_node *node, str Line 102  optimize_tree (union any_node *node, str
102    struct composite_node *n = &node->composite;    struct composite_node *n = &node->composite;
103    assert (is_composite (node->type));    assert (is_composite (node->type));
104    
105      /* If you add to these optimizations, please also add a
106         correctness test in tests/expressions/expressions.sh. */
107    
108    /* x+0, x-0, 0+x => x. */    /* x+0, x-0, 0+x => x. */
109    if ((n->type == OP_ADD || n->type == OP_SUB) && eq_double (n->args[1], 0.))    if ((n->type == OP_ADD || n->type == OP_SUB) && eq_double (n->args[1], 0.))
110      return n->args[0];      return n->args[0];
# Line 115  optimize_tree (union any_node *node, str Line 118  optimize_tree (union any_node *node, str
118    else if (n->type == OP_MUL && eq_double (n->args[0], 1.))    else if (n->type == OP_MUL && eq_double (n->args[0], 1.))
119      return n->args[1];      return n->args[1];
120        
121    /* 0*x, 0/x, x*0, MOD(0,x) => x. */    /* 0*x, 0/x, x*0, MOD(0,x) => 0. */
122    else if (((n->type == OP_MUL || n->type == OP_DIV || n->type == OP_MOD_nn)    else if (((n->type == OP_MUL || n->type == OP_DIV || n->type == OP_MOD_nn)
123              && eq_double (n->args[0], 0.))              && eq_double (n->args[0], 0.))
124             || (n->type == OP_MUL && eq_double (n->args[1], 0.)))             || (n->type == OP_MUL && eq_double (n->args[1], 0.)))
# Line 126  optimize_tree (union any_node *node, str Line 129  optimize_tree (union any_node *node, str
129      return n->args[0];      return n->args[0];
130        
131    /* x**2 => SQUARE(x). */    /* x**2 => SQUARE(x). */
132    else if (n->type == OP_POW && eq_double (n->args[2], 2))    else if (n->type == OP_POW && eq_double (n->args[1], 2))
133      return expr_allocate_unary (e,OP_SQUARE, node);      return expr_allocate_unary (e, OP_SQUARE, n->args[0]);
134    
135    /* Otherwise, nothing to do. */    /* Otherwise, nothing to do. */
136    else    else

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26