develooper Front page | perl.perl5.porters | Postings from July 2005

NaN on platforms that don't support it

Thread Next
From:
Sisyphus
Date:
July 24, 2005 17:24
Subject:
NaN on platforms that don't support it
Message ID:
0bc301c590af$217fd730$e201140a@desktop
Hi,

use warnings;

$x = "NaN";
$x += 1;

$y = "foo";
$y += 1;

print $x, " ", $y, "\n";

__END__

For me, produces:

Argument "foo" isn't numeric in addition (+) at try.pl line 7.
1 1

But on the 2 machines I ran that code on (linux and Win32), IEEE NaN is not
supported - as evidenced by the fact that NaN + 1 == 1. I also checked by
running (as suggested in perlop):

perl -le '$a = NaN; print "No NaN support here" if $a == $a'

So ..... given that IEEE NaN is not supported, shouldn't "NaN" be treated
the same as any other string - in which case the above sample script would
produce the additional warning:

Argument "NaN" isn't numeric in addition (+) at try.pl line 4.

The fact that '$x += 1;' produces no warning implies to me that NaN is being
understood and treated correctly - but that's not the case.

I think the identical situation arises with INF.

(This post is a result of the more-or-less current c.l.p.misc thread "IEEE
NaN screwed up?")

Cheers,
Rob




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