New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wacky modulus behaviour #775
Comments
From gnat@frii.comUntil you do it in separate steps, 'time % -60' is never negative. Nat |
From [Unknown Contact. See original ticket]Nathan Torkington writes:
Is not it that time may take an argument, and % may preceed an identifier? Ilya |
From [Unknown Contact. See original ticket]Ilya Zakharevich writes:
I don't think so. The second case, which doesn't give an argument to Nat |
From [Unknown Contact. See original ticket]Nathan Torkington <gnat@frii.com> wrote
Nope. It's a false optimisation. The last time it showed up, the perl -le 'print time; print time*1000' I don't recall the details, but basically Perl is saying something like I also don't recall why this didn't get fixed - whether it was just Mike Guy |
From @gsarOn Sat, 23 Oct 1999 16:24:17 BST, "M.J.T. Guy" wrote:
AFAIK this particular bug in modulus has never come up before, or I Sarathy Inline Patch-----------------------------------8<-----------------------------------
Change 4428 by gsar@auger on 1999/10/23 20:28:56
fix accidental C modulo semantics on integer-valued operations
(e.g. caused C<length("abc") % -10> to return 3 rather than -7)
Affected files ...
... //depot/perl/op.c#205 edit
... //depot/perl/t/op/int.t#6 edit
Differences ...
==== //depot/perl/op.c#205 (text) ====
Index: perl/op.c
--- perl/op.c.~1~ Sat Oct 23 13:29:02 1999
+++ perl/op.c Sat Oct 23 13:29:02 1999
@@ -2112,8 +2112,12 @@
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) {
==== //depot/perl/t/op/int.t#6 (xtext) ====
Index: perl/t/op/int.t
--- perl/t/op/int.t.~1~ Sat Oct 23 13:29:02 1999
+++ perl/t/op/int.t Sat Oct 23 13:29:02 1999
@@ -1,9 +1,7 @@
#!./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
if (int(1.234) == 1) {print "ok 1\n";} else {print "not ok 1\n";}
@@ -15,3 +13,12 @@
$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";
+}
End of Patch. |
From @gisleGurusamy Sarathy <gsar@ActiveState.com> writes:
Is this safe? Under 'use integer' you get the %-operator as implemented by C and C use integer; Regards, |
From @gsarOn 24 Oct 1999 12:25:01 +0200, Gisle Aas wrote:
Good point, but I think we could do somewhat better. Sarathy Inline Patch-----------------------------------8<-----------------------------------
Change 4441 by gsar@auger on 1999/10/24 14:33:11
test in change#4428 needs strict interpretation of C modulus
Affected files ...
... //depot/perl/t/op/int.t#8 edit
Differences ...
==== //depot/perl/t/op/int.t#8 (xtext) ====
Index: perl/t/op/int.t
--- perl/t/op/int.t.~1~ Sun Oct 24 07:33:15 1999
+++ perl/t/op/int.t Sun Oct 24 07:33:15 1999
@@ -25,5 +25,6 @@
{
use integer;
$x = length("abc") % -10;
- print $x == 3 ? "ok 6\n" : "# expected 3, got $x\nnot ok 6\n";
+ $y = (3/-10)*-10;
+ print $x+$y == 3 && abs($x) < 10 ? "ok 6\n" : "not ok 6\n";
}
End of Patch. |
Migrated from rt.perl.org#1700 (status was 'resolved')
Searchable as RT1700$
The text was updated successfully, but these errors were encountered: