# New Ticket Created by Michael Joyce
# Please include the string: [perl #19500]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=19500 >
Hello.
The core parrot op neg() allows zero to become negative. That shouldn't
happen. I've attached a patch to this email that corrects the problem by
testing if neg() was passed a value of zero. I've also attached a patch that
adds a new test to make sure that zero cannot become negative.
See also http://mathworld.wolfram.com/CountingNumber.html (zero is neither
positive nor negative)
Michael.
PS. I hope I've done this right. Please let me know if I didn't.
-- attachment 1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/46352/36351/45ddee/core.ops.patch
-- attachment 2 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/46352/36352/1d39c1/number.t.patch
Index: core.ops
===================================================================
RCS file: /cvs/public/parrot/core.ops,v
retrieving revision 1.240
diff -u -r1.240 core.ops
--- core.ops 27 Dec 2002 09:33:11 -0000 1.240
+++ core.ops 27 Dec 2002 21:25:37 -0000
@@ -1703,21 +1703,29 @@
=cut
inline op neg(inout INT) {
+ if($1 == 0.0)
+ goto NEXT();
$1 = -($1);
goto NEXT();
}
inline op neg(inout NUM) {
+ if($1 == 0.0)
+ goto NEXT();
$1 = -($1);
goto NEXT();
}
inline op neg(out INT, in INT) {
+ if($2 == 0.0)
+ goto NEXT();
$1 = -($2);
goto NEXT();
}
inline op neg(out NUM, in NUM) {
+ if($2 == 0.0)
+ goto NEXT();
$1 = -($2);
goto NEXT();
}
Index: t/op/number.t
===================================================================
RCS file: /cvs/public/parrot/t/op/number.t,v
retrieving revision 1.27
diff -u -r1.27 number.t
--- t/op/number.t 14 Dec 2002 01:17:04 -0000 1.27
+++ t/op/number.t 27 Dec 2002 21:26:41 -0000
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 36;
+use Parrot::Test tests => 37;
use Test::More;
output_is(<<CODE, <<OUTPUT, "set_n_nc");
@@ -885,6 +885,16 @@
end
CODE
-3.000000
+OUTPUT
+
+output_is(<<CODE, <<OUTPUT, "neg 0.0");
+ set N1, 0
+ neg N1
+ print N1
+ print "\\n"
+ end
+CODE
+0.000000
OUTPUT
output_is(<<CODE, <<OUTPUT, "mul_n_n");