Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Mar 2000 15:10:20 -0400 (AST)
From:      Ian Grigg <iang@systemics.com>
To:        phk@critter.freebsd.dk
Cc:        current@FreeBSD.ORG, perl5-porters@perl.org
Subject:   Re: [ID 20000306.004] unpack(NaN) big baddaboom
Message-ID:  <200003061910.PAA75240@systemics.com>

next in thread | raw e-mail | index | archive | help
More on that!

Lads here took this to heart and put the debugger over the code.

Apparently, Linux uses glibc which sets the flags in FPU to ignore
the cmp-NaN fault.  Then, I guess, Perl picks it up and turns it into
NaN.  OTOH, FreeBSD libraries don't do that, and the FPU causes
the cmp-NaN fault to cause a FP exception.

(Recorded 2nd hand, you won't catch me using debuggers.)

> That is because FreeBSD correctly traps operations on the value NaN.
> 
> Depending on your religion the bug is either in perl itself which
> should be more careful about NaN and Inf values, or in the perl
> script you supply which does something which is patently bogus,
> but nothing which should provoke a FP trap according to IEEE.

I don't know much about religion, but this feels like
a Perl bug to me.  I feed a highlevel command a number
I read off the wire, and it blows up.  As I have no
control over the wire (it's a network) I cannot *not*
handle the number.

> I would argue that as long as your perl script doesn't use the NaN
> in an operation which IEEE documents as giving a trap ( compare of
> two floats for ordered magnitude for instance) then your perl
> interpreter shouldn't either.

Well, in that sense, this is my workaround:

	my $data = $is->read(4);
	#
	#       Damn, FreeBSD throws Floating Point Exception on NaN!
	#
	my $long = unpack("N", $data);
	if ($long == 2143289344)
	{
		return "NaN";
	}

So I'm fine with it for now.  But, as Perl is an interpretive
language, and they are supposed to, on some higher plain of
thought, handle everything thrown at them, I'd rather it just
returned "NaN" like Linux.

Still, I'm fixed!  Thanks for the confirmation.

iang


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003061910.PAA75240>