develooper Front page | perl.perl6.language | Postings from October 2001

Re: NaN semantics

Thread Previous | Thread Next
From:
Tim Conrow
Date:
October 7, 2001 09:52
Subject:
Re: NaN semantics
Message ID:
3BC08906.B16D774A@ipac.caltech.edu
Damian Conway said:
   > > >       print "Inflation rate: " and $inflation = +<>
   > > >                             until $inflation != NaN;
   > > 
   > > This requires that C<NaN != NaN> be false, causing the loop to
continue
   > > until a valid numeric string is entered.

> Err. Are you *sure*? That's an C<until>, not a C<while>, you realize?

Yes. I had to use all my fingers and toes to keep everything straight,
but I think I did. :-) In the semantics you show (different from IEEE
semantics) "NaN==NaN" is true, so "NaN!=NaN" is false, which is why the
loop continues until a valid number is entered.

> >The example can be rewritten
> >
> >       print "Inflation rate: " and $inflation = +<>
> >                             while $inflation != $inflation;

> Err. No it can't.

I meant, if we used IEEE semantics rather than those you showed, the
example could be correctly written as ...

And did I mention it's ugly this way?

Brent Dax said:
> His point was that the NaN IEEE came up with is defined to have NaN !=
> NaN, and that it might be confusing if Perl's behavior wasn't consistent
> with that.  Not that I think NaN != NaN is a particularly good idea, but
> consistency with other languages may be.  If NaN != NaN, then his
> example is correct.

Thank you Brent. Brevity and clarity; what concepts! I must try them
sometime.

-- Tim Conrow

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About