X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=inline;f=src%2Fexpressions%2Foptimize.c;h=c6e919488f20fe044fa9b65dbee7a672b8497c6d;hb=5a33cc6d78fe87ff5e9bd32ea4af3f895e4ad2fc;hp=268141627e7cf98031627e0e2d7f7c2256336d33;hpb=d807ad29cc0d3caa4f0e04ee4b75c70a225cfeaf;p=pspp-builds.git diff --git a/src/expressions/optimize.c b/src/expressions/optimize.c index 26814162..c6e91948 100644 --- a/src/expressions/optimize.c +++ b/src/expressions/optimize.c @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. */ #include #include "private.h" @@ -102,6 +102,9 @@ optimize_tree (union any_node *node, struct expression *e) struct composite_node *n = &node->composite; assert (is_composite (node->type)); + /* If you add to these optimizations, please also add a + correctness test in tests/expressions/expressions.sh. */ + /* x+0, x-0, 0+x => x. */ if ((n->type == OP_ADD || n->type == OP_SUB) && eq_double (n->args[1], 0.)) return n->args[0]; @@ -115,7 +118,7 @@ optimize_tree (union any_node *node, struct expression *e) else if (n->type == OP_MUL && eq_double (n->args[0], 1.)) return n->args[1]; - /* 0*x, 0/x, x*0, MOD(0,x) => x. */ + /* 0*x, 0/x, x*0, MOD(0,x) => 0. */ else if (((n->type == OP_MUL || n->type == OP_DIV || n->type == OP_MOD_nn) && eq_double (n->args[0], 0.)) || (n->type == OP_MUL && eq_double (n->args[1], 0.))) @@ -126,8 +129,8 @@ optimize_tree (union any_node *node, struct expression *e) return n->args[0]; /* x**2 => SQUARE(x). */ - else if (n->type == OP_POW && eq_double (n->args[2], 2)) - return expr_allocate_unary (e,OP_SQUARE, node); + else if (n->type == OP_POW && eq_double (n->args[1], 2)) + return expr_allocate_unary (e, OP_SQUARE, n->args[0]); /* Otherwise, nothing to do. */ else