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

Discussion in 'Perl Misc' started by PeterSShenkin, Aug 22, 2005.

  1. 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.
    PeterSShenkin, Aug 22, 2005
    #1
    1. Advertising

  2. PeterSShenkin

    Guest

    PeterSShenkin wrote:
    >
    > 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
    , Aug 22, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ingo Nolden

    IEEE floating point

    Ingo Nolden, Jun 13, 2004, in forum: C++
    Replies:
    2
    Views:
    483
    Ingo Nolden
    Jun 13, 2004
  2. Lionel B
    Replies:
    0
    Views:
    1,057
    Lionel B
    Sep 23, 2004
  3. GooglePoster
    Replies:
    1
    Views:
    535
    Paul Richards
    Aug 29, 2003
  4. Madhusudan Singh
    Replies:
    2
    Views:
    354
    Ben Caradoc-Davies
    Oct 15, 2005
  5. Benjamin Rutt
    Replies:
    2
    Views:
    5,502
Loading...

Share This Page