BookML test: The algorithms bundle

Rogério Brito

BookML

v0.28.5

0.8.8

2018/12/01

  S0S\leftarrow 0
1:   S0S\leftarrow 0
Algorithm 1 Calculate y=xny=x^{n}
0:   n0x0n\geq 0\vee x\neq 0
0:   y=xny=x^{n}
  y1y\leftarrow 1
  if n<0n<0 then
     X1/xX\leftarrow 1/x
     NnN\leftarrow-n
  else
     XxX\leftarrow x
     NnN\leftarrow n
  end if
  while N0N\neq 0 do
     if NN is even then
        XX×XX\leftarrow X\times X
        NN/2N\leftarrow N/2
     else {NN is odd}
        yy×Xy\leftarrow y\times X
        NN1N\leftarrow N-1
     end if
  end while