Mailing List Archive

Bug: problems with -0
I have managed to obtain the value -0 from perl;
from -$a or -1 * $a, where $a = 0.

This only caused me problems when I came to use the value as a boolean:
-0 started life as false; but once I treated it as a string it became
true.

This is perl5.001m.

Robin Barker

In the -e's below '-$a' is replaced by '-1*$a'
and/or '$b, ' is replaced by '$b .'.

$ perl -lwe 'use strict; my $a = 0; my $b = -$a;
print $b, " is ", $b ? "true" : "false";'
-0 is false
$ perl -lwe 'use strict; my $a = 0; my $b = -1*$a;
print $b, " is ", $b ? "true" : "false";'
-0 is false
$ perl -lwe 'use strict; my $a = 0; my $b = -$a;
print $b ." is ", $b ? "true" : "false";'
-0 is true
$ perl -lwe 'use strict; my $a = 0; my $b = -1*$a;
print $b ." is ", $b ? "true" : "false";'
-0 is true
$ perl -v

This is perl, version 5.001

Unofficial patchlevel 1m.

Copyright 1987-1994, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.

_________________________________________________________________
Robin Barker, | Email: rmb@cise.npl.co.uk
Open Systems Group, | Tel: +44 (0) 181 943 7090
CISE, National Physical Laboratory, | Fax: +44 (0) 181 977 7091
Teddington, Middlesex, UK. TW11 0LW | WWW: http://www.npl.co.uk