(50G) Generalized powering algorithm - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (50G) Generalized powering algorithm (/thread-3172.html) |
(50G) Generalized powering algorithm - Gerald H - 02-22-2015 10:04 AM Input Z: Integer A Y: Integer B X: Programme C For the above input the programme GENPOW below returns the integer A to the Bth power of programme C. For C=<< + >> GENPOW returns the product of A & B. For C=<< * >> GENPOW returns A^B. ForC=<< ? >> GENPOW returns the Bth Fibonacci number, etc. :: CK3&Dispatch # FF8 :: 3UNROLL FPTR2 ^DupQIsZero? case2drop FPTR2 ^DROPZ1 FPTR2 ^DupZIsOne? case DROPSWAPDROP OVERUNROT FPTR2 ^Z>ZH FPTR2 ^ZBits #1- ZERO_DO SWAPDUP 5PICK EVAL SWAP ISTOP-INDEX #1- FPTR2 ^ZBit? IT :: SWAP3PICK 5PICK EVAL SWAP ; LOOP SWAP 4UNROLL3DROP ; ; |