Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How do I create/detect/handle Infinity?

by shmem (Chancellor)
on Jul 25, 2009 at 11:04 UTC ( #783158=note: print w/replies, xml ) Need Help??


in reply to How do I create/detect/handle Infinity?

Creating Inf/NaN:

use Devel::Peek; $inf = (~@~)**(~@~); $nan = $inf / $inf; Dump $_ for $inf, $nan; __END__ SV = NV(0x9e15f84) at 0x9dfc11c REFCNT = 2 FLAGS = (NOK,pNOK) NV = inf SV = NV(0x9e15f9c) at 0x9dfc59c REFCNT = 2 FLAGS = (NOK,pNOK) NV = nan

Detecting Inf/NaN: since they are numeric values, Inf and NaN can be tested for with the numeric equality/inequality operators == and !=. For Inf, greater and less also work.

Handling: not useful ;-)

Devel::Peek

Replies are listed 'Best First'.
Re: Answer: How do I create/detect/handle Infinity?
by ysth (Canon) on Jul 26, 2009 at 06:26 UTC
      NaN doesn't test as == anything, even another NaN.

      I was wondering:
      unless ($x <= $inf) { print "\$x is definitely a NaN\n" } else { print "\$x is definitely NOT a NaN\n" }
      Is that reliable ? ... assuming, of course, that $inf is in fact + infinity, and that there are no bugs present.
      Seems to me that ought to be good enough.

      Cheers,
      Rob

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2021-09-25 09:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?