From: Gurusamy Sarathy Date: Sat, 23 Oct 1999 20:28:56 +0000 (+0000) Subject: fix accidental C modulo semantics on integer-valued operations X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4bb9f687ed0930c988c412c4c28bd2a535612894;p=p5sagit%2Fp5-mst-13.2.git fix accidental C modulo semantics on integer-valued operations (e.g. caused C to return 3 rather than -7) p4raw-id: //depot/perl@4428 --- diff --git a/op.c b/op.c index f38b26c..7fae9f7 100644 --- a/op.c +++ b/op.c @@ -2112,8 +2112,12 @@ Perl_fold_constants(pTHX_ register OP *o) return o; if (!(PL_hints & HINT_INTEGER)) { - if (type == OP_DIVIDE || !(o->op_flags & OPf_KIDS)) + if (type == OP_MODULO + || type == OP_DIVIDE + || !(o->op_flags & OPf_KIDS)) + { return o; + } for (curop = ((UNOP*)o)->op_first; curop; curop = curop->op_sibling) { if (curop->op_type == OP_CONST) { diff --git a/t/op/int.t b/t/op/int.t index eb060ac..c01c12a 100755 --- a/t/op/int.t +++ b/t/op/int.t @@ -1,8 +1,6 @@ #!./perl -# $RCSfile: int.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:00 $ - -print "1..4\n"; +print "1..6\n"; # compile time evaluation @@ -15,3 +13,12 @@ if (int(-1.234) == -1) {print "ok 2\n";} else {print "not ok 2\n";} $x = 1.234; if (int($x) == 1) {print "ok 3\n";} else {print "not ok 3\n";} if (int(-$x) == -1) {print "ok 4\n";} else {print "not ok 4\n";} + +$x = length("abc") % -10; +print $x == -7 ? "ok 5\n" : "# expected -7, got $x\nnot ok 5\n"; + +{ + use integer; + $x = length("abc") % -10; + print $x == 3 ? "ok 6\n" : "# expected 3, got $x\nnot ok 6\n"; +}