HP Forums

Full Version: (50G) Generalized powering algorithm
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
;
;
Reference URL's