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

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

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
June 16, 2002 04:57
Subject:
Re: [PATCH] pp.c:pp_pow() -- quit when you're done
Message ID:
20020616114530.GA301@Bagpuss.unfortu.net
On Sat, Jun 15, 2002 at 06:56:12PM -0500, Craig A. Berry wrote:
> 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.

Not really. I wasn't too worried about tweaking the performance of the
integer bits of the pp_pow loop once it was working (in log(n) time).
Having looked at how GNU bc does the calculation, I realised that there
was at least one way of rewriting it (sorry, I forget how offhand) that
would use slightly less calculation each iteration.

For information (which I don't think has reached p5p) the reason for having
messy loops in pp_pow rather than using pow() or log(), exp() and a multiply
is that on Irix with longdoubles, 2**31 was giving a floating point value
slightly *less* than 1<<31, which was really screwing up some tests.
(and by implication (nearly) every perl programmer's assumption that 2**n
is an integer)

Nicholas Clark
-- 
Even better than the real thing:	http://nms-cgi.sourceforge.net/

Thread Previous | 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