From 886a446526bf7a98f554b67775a504fa1d5d08e9 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Mon, 25 Oct 2010 21:29:24 -0700 Subject: [PATCH] -$zero should not modify $zero With change a5b92898, negation started modifying numeric arguments, causing problems for modules like Data::Float. --- pp.c | 2 +- t/op/numconvert.t | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pp.c b/pp.c index 6811ba0..c99d697 100644 --- 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 ); } diff --git a/t/op/numconvert.t b/t/op/numconvert.t index ce78809..d353861 100644 --- a/t/op/numconvert.t +++ b/t/op/numconvert.t @@ -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"; -- 2.7.4