Article View: comp.lang.postscript
Article #3530Re: GCD algorithm
From: Glenn Reid
Date: Thu, 01 Nov 1990 23:56
Date: Thu, 01 Nov 1990 23:56
43 lines
2134 bytes
2134 bytes
In article <90305.105824CXT105@psuvm.psu.edu> CXT105@psuvm.psu.edu (Christopher Tate) writes:
>In article <1990Oct31.182705.3184@light.uucp>, bvs@light.uucp (Bakul Shah) says:
>
>>- To justify posting this to a PostScript group, here is a faster
>> version of basically the same algorithm:
>>
>> /gcd { % given m, n on the stack
>> dup 3 1 roll mod % leaves n, m mod n on the stack
>> dup 0 eq {
>> pop % leaves n on the stack when done
>> } {
>> gcd % find gcd of the new pair
>> } ifelse
>> } bind def
>>
[ stuff deleted ]
>And, for everyone who's been following this, the version of the GCD algorithm
>shown above IS much faster than mine -- use it instead! Mine was a quick-
>and-dirty rewrite of a Rexx version of the algorithm, and so was not at all
>suited to the real stack-handling capabilities of PostScript.
I put in the newer version of "gcd" and it went a bit faster. Even more
dramatic was to bind the for loop at the end, like this:
0 3 limit
{
dup frac mul /phi exch def % calculate phi
/theta exch def % recalculate theta
theta limit div 1.0 1.0 sethsbcolor % go through all colors
theta cos diff mul phi cos a mul add % this is x
theta sin diff mul phi sin a mul add % this is y
2 copy lineto stroke moveto % same as x y lineto stroke x y moveto
} bind for
% ^^^^ (add "bind" here)
(Glenn) cvn pop
--
Glenn Reid RightBrain Software
glenn@heaven.woodside.ca.us PostScript/NeXT developers
..{adobe,next}!heaven!glenn 415-851-1785
Technical Details
Message-ID:
<307@heaven.woodside.ca.us>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!pacbell.com!decwrl!adobe!heaven!glennReferences:
<90305.105824CXT105@psuvm.psu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!pacbell.com!decwrl!adobe!heaven!glenn From: glenn@heaven.woodside.ca.us (Glenn Reid) Newsgroups: comp.lang.postscript Subject: Re: GCD algorithm Message-ID: <307@heaven.woodside.ca.us> Date: 1 Nov 90 23:56:47 GMT References: <90305.105824CXT105@psuvm.psu.edu> Reply-To: glenn@heaven.woodside.ca.us (Glenn Reid) Organization: RightBrain Software, Woodside, CA Lines: 43