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

NaN semantics

Thread Next
From:
Tim Conrow
Date:
October 6, 2001 22:47
Subject:
NaN semantics
Message ID:
3BBFED1D.3090A98B@ipac.caltech.edu
Semantic confusion alert!

EX3 (great document!) sez:

>       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. For IEEE-type NaN semantics,
that isn't so: C<NaN != NaN> is true! Try:

/* x86 Linux + gcc */
#include <math.h>
main()
{
  double nan = sqrt(-1);

  if(! (nan == nan)) printf("%f == %f is false\n",nan,nan);
  if(   nan != nan)  printf("%f != %f is true\n",nan,nan);
}

Perl6 can, of course, define any semantics for NaN that it chooses, but
there will be some confusion and dissonance if the choice above is made;
i.e. to make C<NaN != NaN> false.

The example can be rewritten

       print "Inflation rate: " and $inflation = +<>
                             while $inflation != $inflation;

That is ugly, non-intuitive and ugly; and non-intuitive too. But
inconsistency with a long accepted standard is also ungood. Perhaps we
need to write it thus:

       print "Inflation rate: " and $inflation = +<>
                             while $inflation.isnan;

or some such?

-- Tim Conrow

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