develooper Front page | perl.perl5.changes | Postings from February 2002

Change 14613: [PATCH] Re: Modulus operator inconsistency

From:
Jarkko Hietaniemi
Date:
February 9, 2002 14:15
Subject:
Change 14613: [PATCH] Re: Modulus operator inconsistency
Message ID:
200202092215.g19MF5e25361@smtp3.ActiveState.com
Change 14613 by jhi@alpha on 2002/02/09 21:12:12

	Subject: [PATCH] Re: Modulus operator inconsistency
	From: Nicholas Clark <nick@unfortu.net>
	Date: Sat, 9 Feb 2002 21:00:13 +0000
	Message-ID: <20020209210013.GG410@Bagpuss.unfortu.net>

Affected files ...

.... //depot/perl/op.c#483 edit
.... //depot/perl/t/op/arith.t#13 edit

Differences ...

==== //depot/perl/op.c#483 (text) ====
Index: perl/op.c
--- perl/op.c.~1~	Sat Feb  9 14:15:05 2002
+++ perl/op.c	Sat Feb  9 14:15:05 2002
@@ -2498,30 +2498,6 @@
     }
 
   nope:
-    if (!(PL_opargs[type] & OA_OTHERINT))
-	return o;
-
-    if (!(PL_hints & HINT_INTEGER)) {
-	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) {
-		if (SvIOK(((SVOP*)curop)->op_sv))
-		    continue;
-		return o;
-	    }
-	    if (PL_opargs[curop->op_type] & OA_RETINTEGER)
-		continue;
-	    return o;
-	}
-	o->op_ppaddr = PL_ppaddr[++(o->op_type)];
-    }
-
     return o;
 }
 

==== //depot/perl/t/op/arith.t#13 (xtext) ====
Index: perl/t/op/arith.t
--- perl/t/op/arith.t.~1~	Sat Feb  9 14:15:05 2002
+++ perl/t/op/arith.t	Sat Feb  9 14:15:05 2002
@@ -1,6 +1,6 @@
 #!./perl -w
 
-print "1..130\n";
+print "1..132\n";
 
 sub try ($$) {
    print +($_[1] ? "ok" : "not ok"), " $_[0]\n";
@@ -245,7 +245,23 @@
 tryeq 126, -5.5 / -2, 2.75;
 
 # Bluuurg if your floating point can't accurately cope with powers of 2
+# [I suspect this is parsing string->float problems, not actual arith]
 tryeq_sloppy 127, 18446744073709551616/1, 18446744073709551616; # Bluuurg
 tryeq 128, 18446744073709551616/2, 9223372036854775808;
 tryeq 129, 18446744073709551616/4294967296, 4294967296;
 tryeq 130, 18446744073709551616/9223372036854775808, 2;
+
+{
+  # The peephole optimiser is wrong to think that it can substitute intops
+  # in place of regular ops, because i_multiply can overflow.
+  # Bug reported by "Sisyphus" <kalinabears@hdc.com.au>
+  my $n = 1127;
+
+  my $float = ($n % 1000) * 167772160.0;
+  tryeq 131, $float, 21307064320;
+
+  # On a 32 bit machine, if the i_multiply op is used, you will probably get
+  # -167772160. It's actually undefined behaviour, so anything may happen.
+  my $int = ($n % 1000) * 167772160;
+  tryeq 132, $int, 21307064320;
+}
End of Patch.




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About