in reply to Re^4: NaNs are true
in thread NaNs are true

What happens if you add NaN to zero? i.e.

if ( 0 + $MPFR_NaN_obj )
I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.

Replies are listed 'Best First'.
Re^6: NaNs are true
by syphilis (Archbishop) on Mar 01, 2011 at 02:56 UTC
    What happens if you add NaN to zero?

    The usual rules apply. NaN+0 equals Nan, so ( 0 + $MPFR_NaN_obj ) returns a Math::MPFR object (courtesy of overloading of '+') that has a value of NaN, which is false.

    Cheers,
    Rob
      ... has a value of NaN, which is false.

      Ok, I'm confused. In your OP, you say NaNs are true. Now you're saying they're false.

      Update: I see, you're talking about your overloaded version, which changes the "sign" of NaN. Ok, I agree that changing that is a Bad Idea in general, because of the violation of expectations.

      So, I guess you'll be stuck (assuming you ditch your overloaded version) doing an explicit test for NaN...

      if ( $obj == NaN or $obj ) # true if true or NaN
      in which case, you could wrap it in a new method:
      sub isTrue # ! { my $obj = shift; $obj == NaN || $obj }