Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: Answer: How do I create/detect/handle Infinity?

by ysth (Canon)
on Jul 26, 2009 at 10:12 UTC ( #783287=note: print w/replies, xml ) Need Help??

in reply to Re^2: Answer: How do I create/detect/handle Infinity?
in thread math

Yes. Other ways:
$isnan = ($x != $x); $isnan = ! defined($x <=> 0);

Replies are listed 'Best First'.
Re^4: Answer: How do I create/detect/handle Infinity?
by syphilis (Chancellor) on Jul 26, 2009 at 12:07 UTC
    $isnan = ! defined($x <=> 0);

    Ooow ... wasn't aware that perl did that.
    In the mpfr library, the mpfr_cmp(x,y) function will return -1 if x<y, +1 if x>y. Otherwise it returns 0 (and sets the erange flag iff one/both of the arguments is a nan).

    So, I'm left wondering whether, in Math::MPFR (which more-or-less wraps the mpfr library), the spaceship operator (which overloads the mpfr_cmp function) should:
    a) adhere to mpfr library behaviour and return 0 and set the erange flag when nans are involved;
    b) adhere to perl behaviour and return undef when nans are involved.

    If b), then there's also the question of whether the erange flag should still be set.

    Interested to hear any thoughts on that.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://783287]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2018-01-18 16:17 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (213 votes). Check out past polls.