From: Stephen McCamant Date: Fri, 18 Jul 2003 02:26:14 +0000 (-0400) Subject: Re: Oops - Can't calculate our powers X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0615a99403886355a89a1cb45b8c609e4424870a;p=p5sagit%2Fp5-mst-13.2.git Re: Oops - Can't calculate our powers Message-ID: <16151.37638.162561.84142@syllepsis.MIT.EDU> p4raw-id: //depot/perl@20167 --- diff --git a/pp.c b/pp.c index 910101a..537606e 100644 --- a/pp.c +++ b/pp.c @@ -972,6 +972,7 @@ PP(pp_pow) register unsigned int highbit = 8 * sizeof(UV); register unsigned int lowbit = 0; register unsigned int diff; + bool odd_power = (power & 1); while ((diff = (highbit - lowbit) >> 1)) { if (baseuv & ~((1 << (lowbit + diff)) - 1)) lowbit += diff; @@ -994,7 +995,7 @@ PP(pp_pow) } } SP--; - if (baseuok || !(power & 1)) + if (baseuok || !odd_power) /* answer is positive */ SETu( result ); else if (result <= (UV)IV_MAX) diff --git a/t/op/pow.t b/t/op/pow.t index 2e1d29f..845e0ff 100644 --- a/t/op/pow.t +++ b/t/op/pow.t @@ -16,7 +16,10 @@ my @pow = ([3,30,1e-14], [4,32,0], [5,20,1e-14], [2.5, 10,,1e-14], [-2, 69,0]); my $tests; $tests += $_->[1] foreach @pow; -plan tests => 1 + $bits_in_uv + $tests; +plan tests => 2 + $bits_in_uv + $tests; + +# This gave positive 27 before change #20167 +is((-3)**3, -27, "(negative int) ** (odd power) is negative"); # Ought to be 32, 64, 36 or something like that.