-$zero should not modify $zero
authorFather Chrysostomos <sprout@cpan.org>
Tue, 26 Oct 2010 04:29:24 +0000 (21:29 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 26 Oct 2010 04:29:50 +0000 (21:29 -0700)
With change a5b92898, negation started modifying numeric arguments,
causing problems for modules like Data::Float.

pp.c
t/op/numconvert.t

diff --git a/pp.c b/pp.c
index 6811ba0..c99d697 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -2457,7 +2457,7 @@ PP(pp_negate)
        SV * const sv = TOPs;
        const int flags = SvFLAGS(sv);
 
-        if( looks_like_number( sv ) ){
+        if( !SvNIOK( sv ) && looks_like_number( sv ) ){
            SvIV_please( sv );
         }   
 
index ce78809..d353861 100644 (file)
@@ -260,7 +260,7 @@ for my $num_chain (1..$max_chain) {
 }
 
 # Tests that use test.pl start here.
-BEGIN { $::additional_tests = 3 }
+BEGIN { $::additional_tests = 4 }
 
 curr_test($test);
 
@@ -268,3 +268,6 @@ ok(-0.0 eq "0", 'negative zero stringifies as 0');
 ok(!-0.0, "neg zero is boolean false");
 my $nz = -0.0; "$nz";
 ok(!$nz, 'previously stringified -0.0 is boolean false');
+$nz = -0.0;
+is sprintf("%+.f", - -$nz), sprintf("%+.f", - -$nz),
+  "negation does not coerce negative zeroes";