From: Gurusamy Sarathy Date: Wed, 31 May 2000 22:37:51 +0000 (+0000) Subject: buggy modulus on UVs introduced by change#3378 (resulted in X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d658dc55c1a5a1e82545e617134daabc3276b047;p=p5sagit%2Fp5-mst-13.2.git buggy modulus on UVs introduced by change#3378 (resulted in 4063328477 % 65535 amounting to 27406, instead of 27407) p4raw-link: @3378 on //depot/perl: 25da4f389200e19df8aa50bcef9af9506f48ed2e p4raw-id: //depot/perl@6179 --- diff --git a/pp.c b/pp.c index d0fe911..fc3a4a7 100644 --- a/pp.c +++ b/pp.c @@ -969,7 +969,7 @@ PP(pp_modulo) NV dright; NV dleft; - if (SvIOK(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)) { + if (SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)) { IV i = SvIVX(POPs); right = (right_neg = (i < 0)) ? -i : i; } @@ -981,7 +981,7 @@ PP(pp_modulo) dright = -dright; } - if (!use_double && SvIOK(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)) { + if (!use_double && SvIOK_notUV(TOPs) && !SvNOK(TOPs) && !SvPOK(TOPs)) { IV i = SvIVX(POPs); left = (left_neg = (i < 0)) ? -i : i; } diff --git a/t/op/arith.t b/t/op/arith.t index fe2f0f4..5b04f93 100755 --- a/t/op/arith.t +++ b/t/op/arith.t @@ -1,6 +1,6 @@ #!./perl -print "1..8\n"; +print "1..12\n"; sub try ($$) { print +($_[1] ? "ok" : "not ok"), " $_[0]\n"; @@ -21,3 +21,10 @@ try 5, abs( 13e21 % 4e21 - 1e21) < $limit; try 6, abs(-13e21 % 4e21 - 3e21) < $limit; try 7, abs( 13e21 % -4e21 - -3e21) < $limit; try 8, abs(-13e21 % -4e21 - -1e21) < $limit; + +# UVs should behave properly + +try 9, 4063328477 % 65535 == 27407; +try 10, 4063328477 % 4063328476 == 1; +try 11, 4063328477 % 2031664238 == 1; +try 12, 2031664238 % 4063328477 == 2031664238;