Can Perl be made to use IEEE floating=-point exception handling?

P

PeterSShenkin

I would like "standard" IEEE floating-point behavior, such as log(0)
giving -Inf instead of this being a disallowed operation. Across the
board, I'd like standard production and handling of Infs and NaNs, at
least on ieee machines.

If Perl has to be recompiled specially to do this, that is a
possibility; but if I can get my script to be handled this way with the
standard download, it would be even better. Is there any way to do
this? I'm using a standard CPAN download of Perl 5.8.6 on Linux.

There was a thread on this back in 1997, started by Bob Walton:

http://groups.google.com/group/comp...fbcfd0d9be0f55?q=ieee&rnum=2#c6fbcfd0d9be0f55

What was said then was "this could become the basis of a 'use ieee'
pragma, but a search didn't uncover anything more recent.

Thanks,
-P.
 
J

jl_post

PeterSShenkin said:
I would like "standard" IEEE floating-point behavior, such as log(0)
giving -Inf instead of this being a disallowed operation. Across the
board, I'd like standard production and handling of Infs and NaNs, at
least on ieee machines.


You might try giving the modules Math::BigInt and Math::BigFloat a
shot. They handle Inf and NaN operations.

Unfortunately, this short Perl program (that does a log(0)
operation):

/usr/bin/perl -wl
use strict;
use Math::BigFloat;
print log( Math::BigFloat->new(0) );
__END__

gives "NaN" as a result (instead of "-inf" like you wanted).

However, dividing a negative number by 0 does give "-inf", as
demonstrated by this short Perl program:

perl -lMMath::BigInt=:constant -e "print -1 / 0"

So, it looks like Math::BigInt and Math::BigFloat are partway there
in doing what you want.

Hope this helps, Peter.

-- Jean-Luc Romano
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top