Skip Menu |

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 23686
Status: resolved
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: timothybolshaw [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: "Nan" is a number!
Date: Wed, 29 Nov 2006 05:00:51 +0700
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: "Tim Bolshaw" <timothybolshaw [...] gmail.com>
use Scalar::Util qw\looks_like_number\; my $string = 'Nan'; if ( looks_like_number $string ) { print "$string is a number\n"; } else { print "$string is a string\n"; } It is obvious, of course, what is happening. It tickles my funny bone that 'Not-A-Number' looks like a number. Murphy's law applied: I was processing a word array ... one of the words was "Nan"! -- Tim Bolshaw timothybolshaw@gmail.com Mobile: +66-(0)87 072 5009
Subject: Re: [rt.cpan.org #23686] "Nan" is a number!
Date: Tue, 28 Nov 2006 18:51:20 -0600
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
On Nov 28, 2006, at 4:01 PM, Tim Bolshaw via RT wrote: Show quoted text
> use Scalar::Util qw\looks_like_number\; > > my $string = 'Nan'; > if ( looks_like_number $string ) { > print "$string is a number\n"; > } > else { > print "$string is a string\n"; > } > > It is obvious, of course, what is happening. It tickles my funny > bone that > 'Not-A-Number' looks like a number. Murphy's law applied: I was > processing > a word array ... one of the words was "Nan"!
looks_like_number is a direct mapping onto a C function in the perl source. So it returns true for anything Perl would consider using as a number without giving a warning. NaN and Inf are both strings that are considered valid in a numeric context. Graham.
Subject: Re: [rt.cpan.org #23686] Resolved: "Nan" is a number!
Date: Sat, 9 Dec 2006 20:29:27 +0700
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: "Tim Bolshaw" <timothybolshaw [...] gmail.com>
Well, the response was that a test of 'NaN' against the standard C library routine test for a valid number will state that it is. I understand that (as surely implied by my original report) but if the issue is to be regarded as closed, at least the documentation ought be updated to warn that 'looks like number' does not necessarily mean the value incorporates a single numeric digit : indeed 'Nan' (not a number) and some other word abbreviations look like numbers. The function can be very useful for some (not all) kinds of numeric field validation, but not wider use. In particular, it should not be used to try to disambiguate numeric from non-numeric values. Perhaps there is a need for a 'looks like real-number' function. Tim Bolshaw. On 12/9/06, Graham_Barr via RT <bug-Scalar-List-Utils@rt.cpan.org> wrote: Show quoted text
> > <URL: http://rt.cpan.org/Ticket/Display.html?id=23686 > > > According to our records, your request has been resolved. If you have any > further questions or concerns, please respond to this message. >
-- Tim Bolshaw timothybolshaw@gmail.com Mobile: +66-(0)87 072 5009