[comp.lang.forth] # to the n-th power

rctthdb@dutrun.UUCP (H. de Bruijn) (11/23/90)

The function x**n (x and n integer) is also non-present in standard FIG-FORTH.
Here's a possible implementation (just for fun):

: ^ ( n x -> x**n )
  1 SWAP ROT
  BEGIN DUP 0 <> WHILE
  2 /MOD >R IF
  SWAP OVER * SWAP THEN
  DUP * R> REPEAT
  DROP DROP ;

-- 
* Han de Bruijn; applications engineer | "A little bit of Physics  *
* TUD Computing Centre; P.O. Box 354   | would be NO idleness in   *
* 2600 AJ  Delft; The Netherlands.     | Mathematics" (HdB).       *
* E-mail: rctthdb@dutrun.tudelft.nl ---| Fax: +31 15 78 37 87 -----*