develooper Front page | perl.perl5.porters | Postings from August 2001

Re: inf handling in Perl incomplete

Thread Previous | Thread Next
From:
Kurt D. Starsinic
Date:
August 4, 2001 18:23
Subject:
Re: inf handling in Perl incomplete
Message ID:
20010804182207.A13411@wolfetech.com
On Sat, Aug 04, 2001 at 09:58:43AM -0500, Jarkko Hietaniemi wrote:
> On Sat, Aug 04, 2001 at 10:31:54AM +0200, Tels wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > 
> > This is a bug report for perl from perl_dummy@bloodgate.com,
> > generated with the help of perlbug 1.33 running under perl v5.7.2.
> > 
> > The inf (infinity) handling in Perl is, well, incomplete:

    I've noticed this myself recently.

> Incomplete is a kind way of putting it.  In reality there is
> practically *NO* infinity handling.  I added just a couple of days ago
> support for not saying "isn't numeric" for "Inf", and that pretty much
> is the extent of our "Inf" support.  Someone would need to hack on
> toke.c and sv.c to get e.g. the following things to work:
> 
> 	$a = Inf;
> 	$b = Inf + 1;
> 	print Inf + 2;
> 	if ($c == Inf) { ... }
> 	print "foo\n" if Inf + Inf == Inf;

    Why can't we write sub Inf() { <<insert XS here>> }?  Not that we
necessarily want to, but do we have to do lexer-hacking?

> Whether 1000**1000 should:
> 	
> 	(1) silently return Inf
> 	(2) return Inf and warn under some lexical warning
> 	(3) return Inf and croak, must be eval { } catched
> 
> I don't know.

    I think that, at least in Perl 5, we're doomed by precedent.  Any
builtin that might be expected to return +/-Inf or NaN throws an exception,
and has for many releases.  However, we _could_ create a pragma that changes
the behavior of atan() and its kin . . . .

> The various libcs can't decide whether to call it "Inf", "INF",
> or "Infinity".
> 
> While that someone is at it, "NaN" also needs fixing.  In there one
> needs to move more carefully, since there usually are two kinds:
> "signaling" and "quiet" NaNs.  The first kind gives SIGFPEs, the
> second doesn't.
> 
> 	$x = NaN;
> 	print "goofy\n" if 0/0 == NaN;	# should always print
> 	print "spooky\n" if NaN == NaN; # should never print
> 
> 	print "bar\n" if Inf - Inf == NaN;

    I think that these work correctly in Perl now, except that _getting_
a real NaN is a little harder than saying `$x = NaN'.  I think that you
can say, e.g.:

        use POSIX ':fcntl_h'; $x = DBL_MAX();

    and you'll get a real Inf that DTRT (at least on FreeBSD 4.3).  I'll
check that on Monday.

    - Kurt


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