develooper Front page | perl.vmsperl | Postings from June 2002

[PATCH] pp.c:pp_pow() -- quit when you're done

Thread Next
From:
Craig A. Berry
Date:
June 15, 2002 16:58
Subject:
[PATCH] pp.c:pp_pow() -- quit when you're done
Message ID:
a05111b15b93181a27d6d@[172.16.52.1]
A for loop in pp_pow is constructed in such a way that it squares the 
base again even after it's iterated through all the bits of the 
exponent.  This could be a problem on any system where floating 
overflow causes an exception; I noticed it with the D_FLOAT format on 
OpenVMS Alpha, where it was causing Perl to blow up when running 
p/op/pow.t.  The patch below fixes it by exiting the loop as soon as 
we know we can.

If someone strongly objects to having this test inside the loop, I 
can ifdef it.

--- pp.c;-0	Fri Jun  7 09:24:27 2002
+++ pp.c	Sat Jun 15 15:10:13 2002
@@ -956,6 +956,8 @@
                             result *= base;
                             /* Only bother to clear the bit if it is set.  */
                             power &= ~bit;
+                           /* Avoid squaring base again if we're done. */
+                           if (power == 0) break;
                         }
                     }
                     SP--;
[end of patch]
-- 
________________________________________
Craig A. Berry
mailto:craigberry@mac.com

"... getting out of a sonnet is much more
 difficult than getting in."
                 Brad Leithauser

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About