diff options
author | Father Chrysostomos <sprout@cpan.org> | 2010-10-04 13:58:49 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2010-10-04 13:58:49 -0700 |
commit | afa74577a6e8d7cf96f7c62e4acca52fda973699 (patch) | |
tree | a269635929639ed9dbf10beae4f99382f480a8f7 | |
parent | b20c4ee1fc23699f6cbe3ce96cc8fe6eb4c52c4c (diff) | |
download | perl-afa74577a6e8d7cf96f7c62e4acca52fda973699.tar.gz |
[perl #45133] -0.0 has variable Boolean value
This patch makes -0.0 stringify as "0" (while leaving sprintf %g/%f
unchanged).
-rw-r--r-- | pod/perldelta.pod | 14 | ||||
-rw-r--r-- | sv.c | 4 | ||||
-rw-r--r-- | t/op/numconvert.t | 12 |
3 files changed, 26 insertions, 4 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod index 5cd276e3d4..7e1cca2618 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -131,6 +131,14 @@ The unary negation operator C<-> now treats strings that look like numbers as numbers L<[perl #57706]|http://rt.perl.org/rt3/Public/Bug/Display.html?id=57706>. +=head2 Negative zero + +Negative zero (-0.0), when converted to a string, now becomes "0" on all +platforms. It used to become "-0" on some, but "0" on others. + +If you still need to determine whether a zero is negative, use +C<sprintf("%g", $zero) =~ /^-/> or the L<Data::Float> module on CPAN. + =head1 Deprecations XXX Any deprecated features, syntax, modules etc. should be listed here. @@ -677,6 +685,12 @@ L<[perl #48332]|http://rt.perl.org/rt3/Public/Bug/Display.html?id=48332>. The C<&> C<|> C<^> bitwise operators no longer coerce read-only arguments L<[perl #20661]|http://rt.perl.org/rt3/Public/Bug/Display.html?id=20661>. +=item * + +Stringifying a scalar containing -0.0 no longer has the affect of turning +false into true +L<[perl #45133]|http://rt.perl.org/rt3/Public/Bug/Display.html?id=45133>. + =back =head1 Known Problems @@ -2741,13 +2741,11 @@ Perl_sv_2pv_flags(pTHX_ register SV *const sv, STRLEN *const lp, const I32 flags { dVAR; -#ifdef FIXNEGATIVEZERO if (len == 2 && tbuf[0] == '-' && tbuf[1] == '0') { tbuf[0] = '0'; tbuf[1] = 0; len = 1; } -#endif SvUPGRADE(sv, SVt_PV); if (lp) *lp = len; @@ -2934,12 +2932,10 @@ Perl_sv_2pv_flags(pTHX_ register SV *const sv, STRLEN *const lp, const I32 flags Gconvert(SvNVX(sv), NV_DIG, 0, s); } RESTORE_ERRNO; -#ifdef FIXNEGATIVEZERO if (*s == '-' && s[1] == '0' && !s[2]) { s[0] = '0'; s[1] = 0; } -#endif while (*s) s++; #ifdef hcx if (s[-1] == '.') diff --git a/t/op/numconvert.t b/t/op/numconvert.t index fedef70d40..ce7880990f 100644 --- a/t/op/numconvert.t +++ b/t/op/numconvert.t @@ -38,6 +38,7 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; + require './test.pl'; } use strict 'vars'; @@ -72,6 +73,7 @@ my $st_t = 4*4; # We try 4 initializers and 4 reporters my $num = 0; $num += 10**$_ - 4**$_ for 1.. $max_chain; $num *= $st_t; +$num += $::additional_tests; print "1..$num\n"; # In fact 15 times more subsubtests... my $max_uv = ~0; @@ -256,3 +258,13 @@ for my $num_chain (1..$max_chain) { } } } + +# Tests that use test.pl start here. +BEGIN { $::additional_tests = 3 } + +curr_test($test); + +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'); |