Post Reply 
(50G) Generalized powering algorithm
02-22-2015, 10:04 AM (This post was last modified: 06-15-2017 01:41 PM by Gene.)
Post: #1
(50G) Generalized powering algorithm
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
;
;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)