[perl #36003] Opcode 'mod' fails for negative integers

1 view
Skip to first unread message

Roger Browne

unread,
May 27, 2005, 7:27:36 AM5/27/05
to bugs-bi...@rt.perl.org
# New Ticket Created by Roger Browne
# Please include the string: [perl #36003]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=36003 >


The following pir program:

.sub test @MAIN

$I1 = mod 3, 3
print "3 mod 3 = "
print $I1
print "\n"

$I1 = mod -3, 3
print "-3 mod 3 = "
print $I1
print "\n"

$I1 = mod 3, -3
print "3 mod -3 = "
print $I1
print "\n"

$I1 = mod -3, -3
print "-3 mod -3 = "
print $I1
print "\n"

end
.end

...prints this:

3 mod 3 = 0
-3 mod 3 = 3
3 mod -3 = -3
-3 mod -3 = 0

...but I believe it should print this:

3 mod 3 = 0
-3 mod 3 = 0
3 mod -3 = 0
-3 mod -3 = 0

...according to the documentation at
http://www.parrotcode.org/docs/ops/math.html
and according to this discussion from 2001:
http://www.nntp.perl.org/group/perl.perl6.internals/5496

Regards,
Roger Browne
ro...@eiffel.demon.co.uk

Leopold Toetsch

unread,
May 27, 2005, 9:29:13 AM5/27/05
to perl6-i...@perl.org
Roger Browne (via RT) wrote:

> The following pir program:

[ ... ]

> ...but I believe it should print this:
>
> 3 mod 3 = 0
> -3 mod 3 = 0
> 3 mod -3 = 0
> -3 mod -3 = 0

IMHO too. I've updated intval_mod to consider the case of zero reminder
with negative args (rev 8178).

Thanks for testing,
leo

Reply all
Reply to author
Forward
0 new messages