


!******************************************************************************
%EXTERNALINTEGERFN POWII %ALIAS "f_powii"(%INTEGER IARG,NARG)
!
!     CALCULATES IARG**NARG
!
%INTEGER X,Y
%INTEGER N

X= IARG
Y= 1
N= NARG
%IF N=0 %START
  %IF X#0 %THEN %RESULT= 1 %ELSESTART
    %RESULT= 0
  %FINISH
%FINISH


%IF X=1 %THEN %RESULT= 1
%IF X=-1 %START
  %IF N<0 %THEN N= -N
  %IF N&1=1 %THEN %RESULT= -1 %ELSE %RESULT= 1
%FINISH

%IF N<0 %START
  %RESULT= 0
%FINISH

%IF X=0 %THEN %RESULT= 0

%CYCLE
  %IF N&1#0 %THEN Y= Y*X
  N = N>>1
  %IF N#0 %THEN X= X*X %ELSE %EXIT
%REPEAT

!this error exit does not catch all overflows. The user must beware

%IF Y=0 %START
  %RESULT= 0
%FINISHELSE %RESULT= Y
%END {OF POWII}
!******************************************************************************
%ENDOFFILE
