develooper Front page | perl.perl5.porters | Postings from July 2007

[perl #41190] some alphabetic strings silently accepted as numbers

Thread Next
From:
Steve Peters via RT
Date:
July 24, 2007 13:59
Subject:
[perl #41190] some alphabetic strings silently accepted as numbers
Message ID:
rt-3.6.HEAD-23341-1185310737-1618.41190-15-0@perl.org
On Fri Jan 05 18:33:35 2007, zefram <!-- x --> at fysh.org wrote:
> 
> This is a bug report for perl from zefram <!-- x --> at fysh.org,
> generated with the help of perlbug 1.35 running under perl v5.8.4.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> $ perl -lwe 'print "foo" + 0'
> Argument "foo" isn't numeric in addition (+) at -e line 1.
> 0
> $ perl -lwe 'print "inf" + 0'
> 0
> $ perl -lwe 'print "infinity" + 0'
> 0
> $ perl -lwe 'print "nan" + 0'
> 0
> $
> 
> The strings "inf", "infinity", and "nan" undergo numeric conversion
> to the value zero, just like all other alphabetic strings.  Unlike
> other alphabetic strings, they don't elicit a warning when doing so.
> They should.  There are some other strings with the same broken
>    behaviour.
> 
> Presumably the intent of this exception is that these strings could
> represent not-a-number and infinite floating-point values.  However,
> they're not actually doing so.  0 + NaN should yield NaN, and 0 +
> infinity should yield infinity.  The correct floating point behaviour
> can be observed with Perl:
> 
> $ perl -lwe 'print 1e1000'
> inf
> $ perl -lwe 'print 1e1000 + 0'
> inf
> $ perl -lwe 'print 1e1000/1e1000'
> nan
> $ perl -lwe 'print 1e1000/1e1000 + 0'
> nan
> 
> Thus a true floating-point infinity stringifies as "inf", and a true
> NaN as "nan".
> 

These seem to be working for me with 5.8.8 and bleadperl, but I should
check for some tests for this before closing this bug.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About