Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Not a Number

by robartes (Priest)
on Oct 18, 2002 at 07:22 UTC ( [id://206235]=note: print w/replies, xml ) Need Help??


in reply to Not a Number

You use regexes to check whether something is a valid number. The advantage of this is that you can easily adapt the regexes to whatever your interpretation of a number is. Here's an example out of the Cookbook:
use strict; my $number="3.141529"; print "$number is a C float!\n" if $number=~/^([+-]?)(?=\d|\.\d)\d*(\. +\d*)?([Ee]([+-]?\d+))?$/;
Chapter 2 of the Perl Cookbook provides numerous recipes for dealing with numbers in Perl. It comes highly recommended.

CU
Robartes-

Replies are listed 'Best First'.
Re: Re: Not a Number
by rasta (Hermit) on Oct 18, 2002 at 07:45 UTC
    NaN is an IEEE standard constant which stands for Not a Number. It is returned if an invalid operation exception occurs within an operation.

    For example, sqrt(-1) will return a number with a bit configuration that is recognized as NaN because this operation would result in an imaginary number.

    Therefore regexps don't help us in that issue.

    -- yuriy
      When I tried the sqrt(-1) example, I got the message
      Can't take sqrt of -1 at -e line 1.
      so it would seem that NaN is not used.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://206235]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-03-28 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found