Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

negative modulus test failure

by marvell (Pilgrim)
on Jul 07, 2003 at 10:05 UTC ( [id://271909]=perlquestion: print w/replies, xml ) Need Help??

marvell has asked for the wisdom of the Perl Monks concerning the following question:

I have produced the following from one of the tests that failed on my build of perl 5.8.

perl -v | grep This; perl -Minteger -le 'print 3 % -10'

I get ...

This is perl, v5.8.0 built for i686-linux-64all-ld -3

This is, of course, slightly concerning.

Any thoughts?

--
Steve Marvell

Replies are listed 'Best First'.
Re: negative modulus test failure
by gellyfish (Monsignor) on Jul 07, 2003 at 10:23 UTC
    See the comment in the integer manpage:
    Internally, native integer arithmetic (as provided by your C compiler) is used. This means that Perl's own semantics for arithmetic operations may not be preserved. One common source of trouble is the modulus of negative numbers, which Perl does one way, but your hardware may do another.
    % perl -le 'print (4 % -3)' -2 % perl -Minteger -le 'print (4 % -3)' 1
    Hope that helps.

    /J\
    
Re: negative modulus test failure
by adrianh (Chancellor) on Jul 07, 2003 at 10:18 UTC

    From the documentation on the integer pragma:

    Internally, native integer arithmetic (as provided by your C compiler) is used. This means that Perl's own semantics for arithmetic operations may not be preserved. One common source of trouble is the modulus of negative numbers, which Perl does one way, but your hardware may do another.
Re: negative modulus test failure
by Abigail-II (Bishop) on Jul 07, 2003 at 11:28 UTC
    That's a known glibc issue (happens only with some versions) on Linux. My automated smokes reported this daily, until someone (Jarkko I think) decide to let Perl 'fix' this. It's now special cased in the source - in both the development track and the maintainance track. I think Configure now picks this up, but I could be mistaken.

    Abigail

Re: negative modulus test failure
by marvell (Pilgrim) on Jul 07, 2003 at 10:30 UTC
    So, there's naff all I can do about it then. At least I know where I stand :)

    --
    Steve Marvell

      You can always wrap your modulus code with no integer

      use integer; print 3 % -10, "\n"; { no integer; print 3 % -10, "\n"; };
Re: negative modulus test failure
by RollyGuy (Chaplain) on Jul 08, 2003 at 14:48 UTC
    I ran into a problem with a negative modulus result being different between C and Perl. I posted my similar question here. I thought that the discussion may be of use to you.

    Enjoy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://271909]
Approved by broquaint
Front-paged by Tanalis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2024-03-28 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found